-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJava Sub Array
More file actions
29 lines (27 loc) · 759 Bytes
/
Java Sub Array
File metadata and controls
29 lines (27 loc) · 759 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
29
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
int n,sum=0,c=0;
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
int[] a = new int[n];
for(int i=0;i<n;i++){
a[i] = sc.nextInt();
}
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
sum = 0;
for(int k=i;k<=j;k++)
{
sum+=a[k];
}
if(sum<0)c++;
}
}
System.out.print(c);
}
}