We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Scanner sc=new Scanner(System.in);
int jum=sc.nextInt();
int jumtot=0;
int count=0;
int[] arrJum=new int[jum];
String test="";
for (int i = 0; i < jum; i++) {
int val=sc.nextInt();
arrJum[i]=val;
}
for (int i = 0; i < arrJum.length; i++) {
for (int j = i; j < arrJum.length; j++) {
for (int j2 = i; j2 <= j; j2++) {
jumtot+=arrJum[j2];
test=test+String.valueOf(arrJum[j2]);
}
if(jumtot<0) count++;
test="";
jumtot=0;
}
}
System.out.println(count);
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Subarray
You are viewing a single comment's thread. Return to all comments →
Scanner sc=new Scanner(System.in); int jum=sc.nextInt(); int jumtot=0; int count=0; int[] arrJum=new int[jum]; String test=""; for (int i = 0; i < jum; i++) { int val=sc.nextInt(); arrJum[i]=val;