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 trialRobert Bienkowski
115 PointsCan someone show me this how it should look?
Now replace your name with the firstName variable using the string formatter.
// I have setup a java.io.Console object for you named console
String firstName = "Rob";
console.printf ("%s can code in Java!");
6 Answers
Allie O.
11,601 PointsMake sure to add the firstName variable after your string:
console.printf ("%s can code in Java!", firstName);
Kenneth Love
Treehouse Guest TeacherI'm not a Java programmer but I did this stage. In the stage, Craig printf
s out a string to console
where he put his name in. You need to copy that code but change the sentence that the name gets put into.
Remember, printf
requires two things. The string to format and, ultimately, print, and the values to format the string with. You're only missing the value for formatting the string.
Robert Bienkowski
115 Pointsexactly Ken. And other students may understand it easier because most that do come on here have a basic knowledge of java or have used it. I have never touched it in my life. My games i code use a combination of basic python and php. believe it or not, it's different from what i am used to. so when a situation arises, im thinking of all the things i could do in python.
Kenneth Love
Treehouse Guest TeacherI'm actually the Python teacher here at Treehouse. What Craig is asking you to do is exactly the same as this:
first_name = "Kenneth"
print("%s can code Python!" % first_name)
Or, more my style:
first_name = "Kenneth"
print("{} can code Python!".format(first_name))
Or, in PHP:
$firstName = "Kenneth";
echo sprintf("%s can code PHP!", $firstName);
Just, obviously, in Java.
Hopefully seeing how these are all very similar will help you as you go on!
MUZ140567 Merceline Nhamo
4,739 Pointsi tried but i am failing on challenge task 3 of 3
Robert Bienkowski
115 Pointsyeah i just don't follow. This is supposed to be a learning curve and it's not, explanation format in the challenges just dont help at all. time to go to school i suppose there is no other way around it. for some people it's not so plain english. Thanks Ken for your time.
Kenneth Love
Treehouse Guest TeacherOK, can you walk me through your mental process as you're reading and writing the code? Like, literally, line-by-line, step-by-step.
Robert Bienkowski
115 PointsAWESOME ALLIE! THANKS! lol thats what i was looking for.
Directed to Ken: so when it says Now replace your name with the firstName variable using the string formatter.
This is how i Read it. //now replace your name "Rob" with the firstName variable //-->this is what i see it like: firstName "Rob"; <-- to me thats what firstName varibale means.
Next. //using the string formatter "%s". <--thats what i see. so in a complete format this is how i see it.
String firstName "%s"; lol . When the explanation is written that way i take it literally now, and that's what i come out with
Kenneth Love
Treehouse Guest TeacherSo, assuming your code was:
String firstName = "Rob";
console.printf("Rob can code Java!")
at "Now replace your name with the firstName
variable.", you see that as being in line 1, the line that starts with String
, and not in line 2 in the string that's going to be printed?
Thanks, that'll hopefully help Craig and I make this more obvious to future students.
Robert Bienkowski
115 Pointsyeah i already have a funny feeling when seeing python. cause i can recall the codes better. I do it nearly everyday. First thin i learned in Python about things was print, str, expressions and etc. all that made sense and it was step by step so i picked it up naturally. when to use () or when to use [] and how to save things to memory and etc.. this maybe similar but writing it out is little different and honestly Videos are superb. but explanations is where i go bonkers. It's like studying for a test than next thing you know, the words are worded in a way where you have to dig deep into a part of your brain that understands them. for me it's not so easy cause im used to one method and when it switches. i feel like an idiot