I've got a loop that is controlled by a variable called running
which tells if the program is running or not. I am trying to achieve a loop that the user enters a command, and the program is answering him, but for some reason, It's seems like my String splits if its more than one word, this is what I have tried:
import java.util.Scanner;
public class ScannerTest{
private boolean running = true;
public ScannerTest(){
Scanner s = new Scanner(System.in);
while(running){
String command = s.next();
System.out.println(command);
}
}
}
If I am entering two or more words in the Scanner, It seems to split them.
Input >> Hello what's your name?
Output >> Hello
>> what's
>> your
>> name?
Maybe it's because of the While loop? How can i fix it? Thanks in advance.