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

Elizabeth Ekhuemelo
Elizabeth Ekhuemelo
677 Points

Please could I have some guidance, I am not sure what I am doing wrong at the moment.

I don't understand what I am doing wrong with this printf method.

Name.java
// I have setup a java.io.Console object for you named console

Console console = print.f();
String firstName = "Elizabeth";
console.printf = ("Elizabeth can code in Java!");
Fathima Fas-ha
Fathima Fas-ha
6,847 Points

Console console=System.console(); String firstName="Elizabeth"; console.printf("%s can code in java! ",firstName);

I think that you should write the code like that. try that way. Happy coding!!

2 Answers

Godwin Onuegbu
Godwin Onuegbu
16,460 Points

Console console = print.f(); String firstName = "Elizabeth"; // calling the printf method of the console, you need to pass in the right parameters.' %' and the String Name. See below console.printf = ("%s can code in Java!",firstName);

Hi there! These guys helped you to solve it but didn’t explained ! I am going to try it. So, the first task to declare variable. We will use name, so it is type String. We tipe String (name it) we name it firstName (you can name it as you want, first last , google, baby, dady, what ever you want) and then you use equal sign to say that to variable firstName belongs a text , then you tipe your name. So, to variable firstName belongs text this is how it looks. String firstName=“ Elizabeth “; Now about printf!! We work in console so we have to show that we want it to be printed in consol. We start with word console put dot to say I am not finished and I want to add new function to it. We use printf. So it looks like this. console.printf here we open () to say what we want to be printed. It is not veritable so we do not need equality sign. Function print in general works with semicolons. So everything you want to be protected you need to put in to () . It should look like this. console.printf(“ Elizabeth is learning Java”); now if you want to use your veriable in printf. console.printf(“%s is learning Java”, firstName); %s means String and then you say firstName in the end so it knows what String you want to use. Then it will print Elizabeth is learning Java. I am tipping from my phone and autocorrect is on!! Good luck and happy coding!