Java, nextLine() help

hybridxsv

Junior Member
Jan 18, 2011
5
0
0
Hi, I have this code but for some reason the nextLine() does not get executed, any ideas on why? Any help would be great, thanks.

Code:
public static void menu() {
    Tester getQuestion = new Tester();
    Scanner input = new Scanner(System.in);

    while(Quit == false) {
        System.out.println("Please enter the corresponding menu option:");
        System.out.println("1. 1st Grade");
        System.out.println("2. 2nd Grade");
        System.out.println("3. Quit the Program");
        System.out.print("Enter: ");

        int value;
        String cont = "";

        value = input.nextInt();

        if(value == 3) {
            Quit = true;
        }
        else if (value == 1 || value == 2) {
            getQuestion.GradeOneQuestion();
            System.out.print("Play again? (Y or N) ");

            cont = input.nextLine(); //---------This is the part that doesn't work
            System.out.println("Input was: " + cont);

            if(cont == "N")
                Quit = true;
            }
        }
        else {
            System.out.println("Incorrect number, please type again");
        }

    }
}
 
Last edited:

Aikouka

Lifer
Nov 27, 2001
30,383
912
126
I'm assuming that you get to the println statement and it just prints out a blank every time? I've never worked with Scanner before, but based off what I'm reading here...

http://download.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html#nextLine%28)

It looks to me like nextLine() is only going to get input that already exists in the stream.

I did some Googly searching ( http://answers.yahoo.com/question/index?qid=20090103175947AA5pyjq ) and it seems my thoughts are at least somewhat in the right direction.
 

hybridxsv

Junior Member
Jan 18, 2011
5
0
0
Thanks a lot, yeah I swear yahoo answers have solutions to everything that I'll ever need. I just finished the assignment thanks to that link, thanks!