+ 1
Scanner not working
I did exactly what I did just like other coding websites. import java.util.Scanner; class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); String first; String last; System.out.println("Enter your first name"); first = input.nextLine(); System.out.println("Enter your last name"); last = input.nextLine(); System.out.print(first + last); } } The error says Exception in thread "main" java.util.NoSuchElementException: No line found at java.base/java.util.Scanner.nextLine(Scanner.java:1651) at Main.main(Main.java:17)
4 ответов
+ 7
There‘s nothing wrong with your code. But if you don‘t submit anything, it will throw an error because there is no line to read from. That‘s exactly what the error message is saying.
Here in SoloLearn there is no interactivity except for web based projects. So you have to enter your input before you run the code.
+ 2
On "your program needs input" pop-up, input : ex: Kevin Yao
Kevin (press enter).
Yao (press submit).
You have to enter all needed inputs before running code here..
+ 1
Just use next()method instead of nextLine().
Your code is works fine in another app
May be sololearn compiler is something different 😊
https://code.sololearn.com/c6nUm6b2qj94/?ref=app
+ 1
_cm_ thanks your information I am still confused now it clear.