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)
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();//
0
import java.util.Scanner;
Put that at the top.
0
I did and I still get an error
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.