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

Kenneth Emmanuel Kouadio Ziguy
PLUS
Kenneth Emmanuel Kouadio Ziguy
Courses Plus Student 1,125 Points

I am not sure about what our promptForGuess() method will do

public void promptForGuess(){
   Scanner scanner = new Scanner(System.in);
    System.out.print("Enter a character:  ");
    String guessInput= scanner.nextLine();
  } 

I was wondering if this code String guessInput= scanner.nextLine(); stores the input that the user of our app enterred in this code System.out.print("Enter a character: ");

1 Answer

Hi there,

Yes, and no.

The first line, System.out.print("Enter a character: "); merely prompts the user - it just outputs something to the screen that the user can read.

The next line, String guessInput= scanner.nextLine(); does both the things you mention. The part to the right of the equals sign reads what the user has entered on the keyboard. And the part to the left stores that input in the string variable named guessInput.

So, the end result of the code is as you expected, but the two tasks you mention were carried out by one line of code, i.e. getting user input and storing that input.

I hope that helps.

Steve.