Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Objects (Retired) Creating the MVP Current Progress

Michael Smith
Michael Smith
8,222 Points

Trying to get "Enter a letter:" to display on the line below "Try to solve:---------"

When I run my code in the console it appears like this: Try to solve: ---------Enter a letter:

rather than:

Try to solve:--------- Enter a letter:

How do I fix this?

Thanks!

3 Answers

Jeremiah Shore
Jeremiah Shore
31,168 Points

Michael Smith , you can have the "Enter a letter:" text appear on a new line by adding "%n" after "solve:---------". %n is more platform independent, \n applies to Mac and Linux, and \r\n works on Windows, but %n works universally.

For example:

System.out.print("solve:---------%n");
//could also use System.out.println();
String playerGuess = console.readLine("Enter a letter:  ");

Keep in mind this example is not formatting the blank spaces in the solve string with the letters guessed correctly, but is hard-coded for a simple answer to your question.

Seth Kroger
Seth Kroger
56,405 Points

Make sure you print a "\n" for a new line after the "Try to solve: ----------".

Michael Smith
Michael Smith
8,222 Points

Awesome got it guys. I missed that.