import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
for (int s = 0; s >= 0;) {
int n = sc.nextInt();
s = s + n;
if (s < 0) {
break;
} else {
System.out.println(n);
}
}
}
}
This is my code and im getting error like this:
Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Main.main(Main.java:9)
How to solve this error please help me.