← Quiz: Java Control Flow: all 10 questions
Quiz: Java Control Flow · Question 7 of 10
After int n = sc.nextInt(); the user typed 25 and pressed Enter. What does the next sc.nextLine() return?
After int n = sc.nextInt(); the user typed 25 and pressed Enter. What does the next sc.nextLine() return?
- A."25"
- B.An empty string, because the rest of that line was just the Enter key
- C.The next line the user types
- D.It throws an exception
Answer & explanation
Correct answer: An empty string, because the rest of that line was just the Enter key
nextInt reads only the number. Call an extra nextLine() to skip the leftover line ending.
Can you get the rest right without peeking?
Take the timed Quiz: Java Control Flow quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →