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

guys can someone correct the above code for me .i'm trying all the suggestions given but its not working

guys can someone correct the above code for me . i'm trying all the suggestions given its not working

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Okay, let's try again this time going step by step. :-)

In your post over on this thread (https://teamtreehouse.com/community/how-do-i-write-expressions-using-a-string-formatter) You successfully defined a String variable which we will later pass in to the printf() method in the next 2 tasks,

String firstName="joseph";

Now part 2 tells us to write a string of text in the java console that contains a given sentence. printf() It will say something like this "<YOUR NAME> can code in Java!". You can write your own name into this sentence for now, the challenge should accept it. What's important at this stage is you write something to the console

String firstName="joseph";
System.out.printf("Jonnie can code in Java!");

The final task is about getting practice with format specifiers and it uses the variable we defined in task 1. That's why the sentence said <YOUR NAME> because it's intended to be replaced with the value of firstName. To do this you use a format specifier like %s. You then pass in the name of the variable as an argument like this.

String firstName="joseph";
System.out.printf("%s can code in Java!", firstName);

Hopefully, this will help you see how format specifiers are used in Java to display the values of variables! :-)