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 trialAry de Oliveira
28,298 PointsJava Basics Call the printf method on the console object and make write out "<your Name> can code in Java !"
// I have setup a java.io.Console object for you named console
String firstName ="Ary";
console.printf("Ary");
this no work? why ...
// I have setup a java.io.Console object for you named console
String firstName ="Ary";
console.printf("Ary");
3 Answers
Grigorij Schleifer
10,365 PointsHi Ary,
try this:
// I have setup a java.io.Console object for you named console
String firstName ="Ary";
console.printf("My name is %s ", firstName);
The expression %s helps you to put a String (that you stored inside the "firstName" variable) in your text. Afterward you can change "Ary" to whatever you want. But you donΒ΄t need to change your variable "firstName" inside the parenthesis of the printf statement.
To use this cool function you need a proper syntax. And it is:
console.prinf("Your text %s ", yourVariable);
// console is a name of the Console class that Craig have setup for us before
//the %s will be replaced with a String of your choice
//or you can use more of them
String firstName = "Ary";
String middleName = "de";
String lastName = "Oliveira";
console.printf("I am %s %s %s ", firstName, middleName, lastName);
Let me know if you need mor help
Grigorij
Grigorij Schleifer
10,365 PointsHey Ary,
you are very welcome ! DonΒ΄t stop learning !!!!
Grigorij
Ary de Oliveira
28,298 Pointsthank you very much for your help... i am just start with Java .... thank you...