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

Every time I put in the percent symbol to represent my string it still says it is incorrect. Can I have some help?

I am doing fine on everything else, but it is only when I get to the string parts on the exercise that it doesn't let me continue. It works on the workspace, but as soon as I put it into the exercise, it says its incorrect. When I type in "firstName" to get around it, it tells me to put "%s", so I put it then it says invalid.

IO.java
String firstName = console.readLine("Greg");
String lastName = console.readLine("Delgado");
console.printf("%s");

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! First and foremost, your console.readLine just needs an empty set of parentheses. It's going to read in what the user types and assign whatever they type to that variable. Maybe they typed "Greg", but maybe they typed "Jen". Users are highly unpredictable and we're just going to let them decide what they're putting in for the name. The %s is a token which. simply tells Java "Hey insert a value of a string variable here". But after that token you have to say which string variable it should display there.

Here's an example:

String myName = console.readLine();
console.printf("Hi there, %s!", myName);  // here we tell it to put the value stored in the variable myName where the %s is

If the user were now to enter the name "Greg" then "Hi there, Greg!" would be printed out.

Hope this helps! :sparkles: