How to use Scanner multiple times? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to use Scanner multiple times?

So I want to upload a code to Code Playground that goes like this: 1. User reads a printed menu 2. User enters a value 3. User sees the output on the screen 4. User enters another value and so on This website gives me error, because (I think) it only accepts user's input when running the program for the first time. Is there a workaround? Error i get: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at Program.main(Program.java:24)

29th Jun 2018, 9:06 AM
Verbal13
Verbal13 - avatar
3 Answers
+ 5
Verbal13 Unfortunately there's no workaround as it's how online compiler works. Unlike the program we run it our PC, the server cannot wait for user input indefinitely as the resource was shared by everyone. Therefore if multiple inputs are required, we will need to send it in one-go separated by new-line.
29th Jun 2018, 10:36 AM
Zephyr Koo
Zephyr Koo - avatar
+ 1
Sololearn has a restricted input thing. You have to write input on multiple lines codePlayground to understand.
29th Jun 2018, 9:54 AM
Sad
Sad - avatar
+ 1
Also, you can only write input(whatever number of input you want) once on codePlayground. If you take user input, output something on screen and try to take input again, it will not work on codePlayground.
29th Jun 2018, 9:56 AM
Sad
Sad - avatar