0

what happened

https://code.sololearn.com/c55n7x9Nao6O/?ref=app this is my project when i run it shows this message enter first value enter second value Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at Program.main(Program.java:10)

3rd Jan 2022, 9:38 PM
advanced technology world
5 Antworten
+ 1
The problem is that you use 2 scanners for 1 input app (System.in) , and Java can't handle it like in your code, to correct the bug, just use one scanner (delete the second variable and use first to assign an int to v2) Here is your code : import java.util.Scanner; public class Program { public static void main(String[] args) { System.out.println("enter first value"); Scanner first = new Scanner(System.in); int v1 =first.nextInt(); System.out.println("enter second value"); int v2 =first.nextInt(); System.out.println(v1 + v2); } } Input : 12 56 (you also may use line breaks to separate them) Output : 68 (besides the other strings printed)
3rd Jan 2022, 10:25 PM
VCoder
VCoder - avatar
+ 1
Post your new code please
4th Jan 2022, 6:46 PM
VCoder
VCoder - avatar
+ 1
What was your input ?
5th Jan 2022, 10:51 PM
VCoder
VCoder - avatar
0
i edited my code but there is also error similar to that i don't know what is the selution please help me if you can
4th Jan 2022, 5:57 PM
advanced technology world
5th Jan 2022, 8:29 AM
advanced technology world