I am trying to read some data for a "Question" type, which has an id(int), statement(string) and answer(string). I'am using the code below:
Scanner scanner = new Scanner(System.in);
System.out.print("Id (uniquely!): ");
int id = scanner.nextInt();
System.out.print("Statement : ");
String statement = scanner.next();
System.out.print("Answer: ");
String answer = scanner.next();
If I enter sth like this "Who are you?" for "statement", it doesn't wait to type anything else for "answer" too. But if I do not use spaces in my statement it will work just fine. Also, if I use scanner.nextLine()
, instead of scanner.next()
, it doesn't work properly; it will allow me to introduce only one string for both statement
and answer
.
Does anyone have any idea?