0

How to add a code in Code Playground that uses a Scanner?

In my code I have: //public class Main { private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) {// I created a game that requires multiple input by users. How can I add this code to the playground so it works properly? For now I get the errror: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Unknown Source) at Program.main(Program.java:24)

22nd Jun 2018, 10:40 AM
Verbal13
Verbal13 - avatar
8 Answers
0
I do not understand how to use it. In my code I have lines like this: //choice = scanner.nextInt(); scanner.nextLine(); switch ((choice)) {// How to implement your code? EDIT: I think I did it correctly, but it gives error at this line: //case 1: String answer = scanner.nextLine();//
22nd Jun 2018, 11:23 AM
Verbal13
Verbal13 - avatar
0
import java.util.Scanner; Put that at the top.
23rd Jun 2018, 3:54 AM
BlazingMagpie
BlazingMagpie - avatar
0
I did and I still get an error
24th Jun 2018, 10:28 AM
Verbal13
Verbal13 - avatar
0
i do not have it as a comment. I posted it that way for readability. The error regards one line of code I have shown above.
24th Jun 2018, 4:14 PM
Verbal13
Verbal13 - avatar
25th Jun 2018, 1:30 PM
Verbal13
Verbal13 - avatar