-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmaxsubsum.java
More file actions
29 lines (26 loc) · 813 Bytes
/
maxsubsum.java
File metadata and controls
29 lines (26 loc) · 813 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
public class maxsubsum {
public static void sum(int numbers[])
{
int currsum=0;
int maxsum=Integer.MIN_VALUE;
for(int i =0;i<numbers.length;i++){
int start=i;
for(int j=i;j<numbers.length;j++){
int end=j;
currsum=0;
for(int k=start;k<=end;k++){
currsum += numbers[k];
}
System.out.println(currsum);
if(maxsum<currsum){
maxsum=currsum;
}
}
}
System.out.print("maxsum" + maxsum);
}
public static void main(String args[]){
int numbers[] = {1,-2,6,-1,3};
sum(numbers);
}
}