Scanner input = new Scanner(System.in);
boolean flag = true;
System.out.print("What is your name? ");
flag = true;
while(flag == true){
name = input.next();
fullName = fullName + " " + name;
if(input.hasNext() == false){
flag = false;
}
}
The above code is just a sample of my whole program, but this piece of the code is where I am having problems.
With the above code, the input that I enter into the console is "the one"
. The problem is after input.next()
collects "one"
and then adds it to fullName
, when the code goes to the if statement to check if there is more input (which there is none), the program just hangs. I am using BlueJ
and the program debugger says that the thread is still running but nothing is going on. I'm wondering how do I collect the entire input of "the one"
using a Scanner
?