Scanner not working | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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(; 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( at Main.main(

10th Nov 2020, 5:15 PM
Kevin Yao
Kevin Yao - avatar
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.
10th Nov 2020, 5:39 PM
+ 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..
11th Nov 2020, 3:25 PM
Jayakrishna 🇮🇳
+ 1
Just use next()method instead of nextLine(). Your code is works fine in another app May be sololearn compiler is something different 😊
10th Nov 2020, 5:29 PM
NavyaSri - avatar
+ 1
_cm_ thanks your information I am still confused now it clear.
10th Nov 2020, 5:46 PM
NavyaSri - avatar