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 Strings, Variables, and Formatting

Hezi Akiva
Hezi Akiva
346 Points

why its not working ? String firstName = "hezi"; Console.printf("hello my name is %s",String);

hi i tried to compile this on the editor on the web and it's not working but when i download the eclipse and i compiled it - it work just fine but i had to change the syntax to system.out.println another question is on what syntax should i use ?

2 Answers

Daniel Hartin
Daniel Hartin
18,106 Points

Hi Hezi

You're almost there, you are trying to populate the String.format() method with the variable type not the variable name try the code below and see how you go:

String firstName = "hezi"; 
Console.printf("hello my name is %s",firstName);

Hope this helps

Daniel

Hezi Akiva
Hezi Akiva
346 Points

Hi Daniel thank you for your reply i understand where was my mistake but when i change it - it still gives me an error :\ i even did a copy past and i get an error ....

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hi Hezi,

i formatted your code:

String firstName = "hezi"; 
Console.printf("hello my name is %s",String);

You should replace String with firstName. String is a type, but for printf method you need the name of the String.

And to your second question:

IDE´s like Eclipse can´t deal with console, because they have no console environment. Console class are made for Console applications, not for Eclipse or IntellyJ.

See this:

https://teamtreehouse.com/community/consolereadline-problem

Grigorij

Hezi Akiva
Hezi Akiva
346 Points

thank you for the answer grigorij