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 IO

Rashida Range
Rashida Range
209 Points

What 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 ;(

IO.java
// 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
Rashida Range
209 Points

Thanks for the prompt response and help Salomon! I tried again while waiting for help and finally got to the right syntax...:)

Rashida Range
Rashida Range
209 Points

So Salomon, to be clear the %s represents an already established syntax in Java?

Rashida Range
Rashida Range
209 Points

Muchas gracias Salomon! Te agradezco un monton!!

2 Answers

Salomon Orrego Martinez
Salomon Orrego Martinez
9,137 Points

Hi, 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
Salomon Orrego Martinez
9,137 Points

Rashida 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
Salomon Orrego Martinez
9,137 Points

Con mucho gusto Rashida, si tienes alguna otra duda con mucho gusto la responderΓ© si estΓ‘ en mis conocimientos

Rashida Range
Rashida Range
209 Points

Gracias! Eso, lo voy hacer.