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 trialRashida Range
209 PointsWhat did I do wrong here?
After retrying a few times I kept getting a syntax error that points to the quotation mark behind "%s".... I'm literally puzzled ;(
// I have imported java.io.Console for you. It is a variable called console.
String firstName= console.readLine("Rashida");
String lastName= console.readLine("Range");
console.printf("First name:("%s",firstName);
Rashida Range
209 PointsSo Salomon, to be clear the %s represents an already established syntax in Java?
Rashida Range
209 PointsMuchas gracias Salomon! Te agradezco un monton!!
2 Answers
Salomon Orrego Martinez
9,137 PointsHi, your code should look like these so you can display the name properly:
String firstName= console.readLine("Rashida"); String lastName= console.readLine("Range"); console.printf("First name: %s",firstName);
in case you want to show the name in quotes (") you sholud write your code like these:
String firstName= console.readLine("Rashida"); String lastName= console.readLine("Range"); console.printf("First name: \"%s\"",firstName);
the \" inside the quotes let the machine know that the quote is part of the string
Salomon Orrego Martinez
9,137 PointsRashida the %s means in other words to the printf (print format) that there's gonna be a String in that part of the string you want to print
Salomon Orrego Martinez
9,137 PointsCon mucho gusto Rashida, si tienes alguna otra duda con mucho gusto la responderΓ© si estΓ‘ en mis conocimientos
Rashida Range
209 PointsGracias! Eso, lo voy hacer.
Rashida Range
209 PointsRashida Range
209 PointsThanks for the prompt response and help Salomon! I tried again while waiting for help and finally got to the right syntax...:)