I have given the error which is coming for this problem. can you please tell me the mistake

import java.util.Scanner;

public class chal4 { public static void main(String args[]) {
int sum=0;
while(sum>=0){
Scanner scn = new Scanner(System.in);
int n=scn.nextInt();
sum=sum+n;
if(sum>=0){
System.out.println(n);
}else{
break;
}
}

}

}

xception 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:7)

Hey @kalindiyadav5
logic is fine
just a change

import java.util.*;

public class Main {

public static void main(String args[]) {
	int sum = 0;

// mera change
Scanner scn = new Scanner(System.in);
while (sum >= 0) {
// Scanner scn = new Scanner(System.in);
int n = scn.nextInt();
sum = sum + n;
if (sum >= 0) {
System.out.println(n);
} else {
break;
}
}

}

}

It is still giving the same error

send me UpDated Code

import java.util.*;

public class Main {

public static void main(String args[]) {

int sum = 0;

Scanner scn = new Scanner(System.in);

while (sum >= 0) {

// Scanner scn = new Scanner(System.in);

int n = scn.nextInt();

sum = sum + n;

if (sum >= 0) {

System.out.println(n);

} else {

break;

}

}

}

}

@kalindiyadav5
I have verified code is fine

What should i do then?
as it it giving error . should I submit the code as it is?

@kalindiyadav5
Q I submit the code as it is?
Answer Yes

1 Like

Until the compiler does not run i am not able to submit code because i am getting error.
Now what should i do . should i use the screen in collaborative mode

Send me teamViewer id and Password

ID - 1 350 036 762
pass-2w94bd