Skip to content

Commit 43c9b15

Browse files
Create JavaSubarray.java
1 parent 9909006 commit 43c9b15

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

‎JavaHackerrank/JavaSubarray.java‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.*;
2+
3+
public class test{
4+
public static void main(String[] args){
5+
Scanner sc = new Scanner(System.in);
6+
int n = sc.nextInt();
7+
ArrayList<Integer> a = new ArrayList<Integer>(n);
8+
for(int i = 0; i<n ; i++){
9+
int s = sc.nextInt();
10+
a.add(s);
11+
}
12+
int tot = 0;
13+
for(int i = 0;i<n;i++){
14+
for(int j = i;j<n;j++){
15+
int sum = 0;
16+
for(int k = i;k<=j;k++){
17+
sum+=a.get(k);
18+
}
19+
if(sum<0){
20+
tot++;
21+
}
22+
}
23+
}
24+
System.out.println(tot);
25+
}
26+
}

0 commit comments

Comments
 (0)