- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathJavaSubarray.java
More file actions
Latest commit
28 lines (23 loc) · 695 Bytes
/
Copy pathJavaSubarray.java
File metadata and controls
28 lines (23 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
packageDataStructure;
importjava.util.*;
publicclassJavaSubarray {
publicstaticvoidmain(String[] args) {
Scannerscan = newScanner(System.in);
intcount = scan.nextInt();
int[] arr = newint[count];
for (intx = 0; x < count; x++) {
arr[x] = scan.nextInt();
}
intresult = 0, sum = 0;
for (intx = 1; x <= count; x++) {
for (inty = 0; y <= count - x; y++) {
sum = 0;
for (intz = y; z < y + x; z++) {
sum += arr[z];
}
result += sum < 0 ? 1 : 0;
}
}
System.out.println(result);
}
}