Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Getting Started with Java Receiving Input

'printf' is not working in my system, other print formats are working. Any possible suggestions...

package useful; import java.io.Console;

public class IoName {

    public static void main(String[] args) 
        {
        Console console = System.console();

        String firstName = "Benny";

        console.printf("My name is %s\n", firstName);

        console.printf("%s loves Java Programming\n", firstName);

  }
}
Ken Alger
Ken Alger
Treehouse Teacher

Benny;

Welcome to Treehouse!

Will you please post the code you are trying to use, and is this on your local system or in Workspaces? Let's see if this issue can't be sorted out.

Ken

4 Answers

Hi Ken, In my eclipse, printf method always gives trouble. Here is an example: Thanks in advance.
Benny.

package useful;
import java.io.Console;

public class IoName {

    public static void main(String[] args)  {

        Console console = System.console();

        String firstName = "Benny";

        console.printf("My name is %s\n", firstName);

        console.printf("%s loves Java Programming\n", firstName);

    }

}

Added syntax highlighting for you. :) Also, can you open a command line and type java -version for me, and copy-paste the result here? That'll let me know what version of Java you're using. Thanks!

Thanks Ryan. I am using java 1.8.0_25

Benny

I had some prior knowlage in java before I came here. This is normally how i set up and print a program.

class example { public static void main( String[] args ) { System.out.println( "This is an example." ); } }

This should do the same thing as the program in this video that goes:

import java.io.Console;

public class example { public static void main(String[] args) { Console console = System.console(); console.printf("This is an example."); } }

Both these programs do the same thing, but I prefer the first one. I hadn't even seen the second one till I saw these video's. if console.printf dosent work for you, try System.out.println

Sorry, the placement of the text got screwed up in the comment.

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Benny;

Please see this post for further clarification.

Ken