Skip to content

Commit b05deeb

Browse files
authored
Java Subarray Program
1 parent 68c9cd1 commit b05deeb

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

Java Subarray.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// https://www.facebook.com/abhi.sensharma/posts/1241788872853419
2+
// Subscribed by Abhishek Sharma
3+
4+
import java.io.*;
5+
import java.util.*;
6+
7+
public class Solution {
8+
9+
public static void main(String[] args) {
10+
Scanner sc = new Scanner(System.in);
11+
int n = sc.nextInt();
12+
int [] arr = new int [n];
13+
for(int i = 0; i < n; i ++) {
14+
arr[i] = sc.nextInt();
15+
}
16+
17+
int count = 0, sum = 0;
18+
for(int i = 0; i < n; i ++) {
19+
for(int j = i; j < n; j ++) {
20+
sum += arr[j];
21+
if(sum < 0) count ++;
22+
}
23+
sum = 0;
24+
}
25+
System.out.println(count);
26+
}
27+
}

0 commit comments

Comments
 (0)