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 trialKrista Rotchy
38 Pointscall the printf method on the console object and make it write out "<YOUR NAME> can code in Java!" - I don't get this...
Can someone explain what I am doing wrong with this:
compile.printf String firstNameLastName = "Krista Rotchy";
2 Answers
peter mposhi
Courses Plus Student 495 Pointsimport java.io.Console; public class Introductios { public static void main (String args[]) { Console console=System.console(); String S1=console.readLine("enter your name \n"); console.printf("<%s> can code in java !",S1); System.exit(0); } }
Grigorij Schleifer
10,365 PointsHi Krista,
// I have setup a java.io.Console object for you named console
String firstName; //here you define a new String called firstName
firstName = "Your Name";
// here you initialise a String value ("Your Name") to firstName
//initialisation is like storing a value (String) inside a variable
//a variable represents the value you stored inside youre code
//firstName is a String variable of your Name now
//you can also write String firstName = "YourName"; - its the same
console.printf("%s can code in Java ", firstName);
//the console object is already there, so you dont need to
//do it like this - Console console = new Console(System.in);
//In other words, you dont need to create an object of the Console class
//you will learn about this later on
//the Console object is called "console" so you use it like this - console.
//after calling console use the character(.) to access methods of the Console class
//one method of the console is printf - so now you have - console.printf
//here you open the parenthesis and whrite your text inside " "
//%s is a String representation, where you put your %s, there will be a String like firstName
//so it looks like this ("bla bla %s ", firstName); , dont forget the (,) and name of your String variable after the " "
Happy coding and stay tuned
Grigorij