I have a series of questions being asked to create a deck of flash cards. So far, I can gather questions and answers, provided the questions don't have spaces. If a question does have spaces, the answer is skipped, however if the answer has spaces, there is no problem. Here is a snippet of my code:
System.out.println("What is the question for number " + (cards + 1) + "?");
question = in.next();
System.out.println("What is the answer for number " + (cards + 1) + "?");
answer = in.next();
And here is the resulting output with spaces in a question and an answer:
What is the question for number 1?
This is a question
What is the answer for number 1?
What is the question for number 2?
x
What is the answer for number 2?
This is an answer
What is the question for number 3?
X
Instead of using the next() method, use nextLine() to capture the entire line instead of just the next word:
System.out.println("What is the question for number " + (cards + 1) + "?");
question = in.nextLine();
System.out.println("What is the answer for number " + (cards + 1) + "?");
answer = in.nextLine();
Does that help?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With