// TODO Auto-generated method stub
int sum= 0;
Scanner scn = new Scanner(System.in);
while(sum>=0) {
int n = scn.nextInt();
sum =sum +n;
if(sum>0) {
System.out.println(n);
}
else
break;
sum++;
}
}
}
// TODO Auto-generated method stub
int sum= 0;
Scanner scn = new Scanner(System.in);
while(sum>=0) {
int n = scn.nextInt();
sum =sum +n;
if(sum>0) {
System.out.println(n);
}
else
break;
sum++;
}
}
}
check if the next input exists then only go in the while loop
use scn.hasNext(),it ll pass all the test cases
if this solves your doubt please mark your doubt as resolved 
int sum= 0; Scanner scn = new Scanner(System.in); scn.hasNext(); while(sum>=0) { int n = scn.nextInt(); sum =sum +n; if(sum>0) { System.out.println(n); } else break; sum++; } } }
still getting errors
do
while(sum>=0 && scn.hasNext()) {
that will pass all the test cases
i am still not able to enter the next digit and if i am using do while loop it is showing errors because of brackets
The corrected code:
import java.util.*;
public class Main {
public static void main(String args[]) {Scanner scn = new Scanner(System.in); int sum = 0; while(sum >= 0&& scn.hasNext()){ int n = scn.nextInt(); sum += n; if(sum < 0) break; System.out.println(n); } }}