Simple input challenge

out of 4 only one test case pass
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int [] arr = new int[5];
for(int i = 0;i<=arr.length-1;i++)
{
arr[i] = sc.nextInt();
}
for(int i = 0;i<=arr.length-1;i++)
{
if(arr[i]>=0)
{
System.out.println(arr[i]);
}
else
{
break;
}

	}



}

}

@Naman_Gupta checking it buddy!

@Naman_Gupta buddy you don’t know what will be the input array size so you have to do this question without taking array.

This is the way:-

  1. Put a loop till the END OF INPUT.
  2. Add the new number to the previous sum.
  3. If the sum is positive print the current number.
  4. Otherwise, break the loop.

If your query is resolved then mark the doubt resolved and rate full else feel free to ask!