Test case error

Scanner scn =new Scanner(System.in);
int n=1;
int N=5;
int sum=0;

while(n<=N) {
int x= scn.nextInt() ;
sum=x+sum;

   if (sum<0) {
		break;
	    }else  {
        System.out.println(x); ;
	      }

n++;}

@Laibaqureshi227
hi, where in this question it is written that you have to take only 5 inputs?
Read this line carefully stop processing input after the cumulative sum of all the input becomes negative.

Here is my code for ya reference.
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int sum = 0;

    while(sum >= 0){

        int n = scn.nextInt();
        sum += n;

        if(sum < 0) break;
        System.out.println(n);
    }
}

}

Also if ya query is cleared, mark ya doubt as resolved and rate full!
Happy Coding!

1 Like

I am not able to pass all test cases

@Laibaqureshi227 have you checked my reply above? I have even given ya my code!