+ 1

I'm getting error ,i don't know why this code run successfully in my ide

This doesn't works with nextInt method import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sd = new Scanner(System.in); int password; do{ System.out.println("Write password"); password = sd.nextInt(); } while(password!=8839); } }

22nd Nov 2022, 10:25 AM
Prashant Rai
5 Réponses
+ 6
There is no problem with the code. Error is because of there is no input present to read.. Note that loop continue is the condition is true that is input is not 8839 so again ask the input. Sololearn is not interactive so you need to give all required input at once on the pop-up window , it's before start execution. So try : 1234 < press enter > 8839 < press submit > Runs successfully, that first input 1234 is not password then reads next input, 8839 then condition becomes false. Password is correct so loop terminates. Execution completes without errors... hope it helps..
22nd Nov 2022, 11:00 AM
Jayakrishna 🇮🇳
+ 1
What are your inputs?
22nd Nov 2022, 10:45 AM
Jayakrishna 🇮🇳
0
NoSuchElement exception There is no problem with code because same code run successfully in my ide
22nd Nov 2022, 10:51 AM
Prashant Rai
0
All problem with scanner because scanner has not nextInt method
22nd Nov 2022, 10:51 AM
Prashant Rai
0
Can you write a code?
22nd Nov 2022, 11:16 AM
Prashant Rai