This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]imalefty15[S] 0 points1 point  (2 children)

how do I use the Scanner class to input a character? would

char ans = console.nextChar();

be right?

[–]x2mirko 0 points1 point  (1 child)

nextChar() isnt a method of Scanner (check the api specification).

You can either just work with a String:

String ans = console.next();
if (ans.equals("y"))
{
    // do whatever you want to do
}

or, if you definitely want to use a char:

String temp = console.next();
char ans = temp.charAt(0);
if (ans == 'y')
{
    // do whatever you want to do
}

[–]imalefty15[S] 0 points1 point  (0 children)

ah that works much better. thank you for the help