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)
5 Réponses
+ 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)
+ 1
Post your new code please
+ 1
What was your input ?
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