package com.kangjia; |
|
import java.util.Arrays; |
|
public class Y { |
|
|
|
public void getNumCount(int[] data){ |
|
|
|
|
|
int[] max=new int[5]; |
|
|
|
int max1=0; |
|
int sum1=0; |
|
for(int i=0;(i+1) |
|
sum1=data[i]+data[i+1]; |
|
if(sum1>max1){ |
|
max1=sum1; |
|
} |
|
} |
|
max[0]=max1; |
|
|
|
int max2=0; |
|
int sum2=0; |
|
for(int i=0;(i+2) |
|
sum2=data[i]+data[i+1]+data[i+2]; |
|
if(sum2>max2){ |
|
max2=sum2; |
|
} |
|
} |
|
max[1]=max2; |
|
|
|
int max3=0; |
|
int sum3=0; |
|
for(int i=0;(i+3) |
|
sum3=data[i]+data[i+1]+data[i+2]+data[i+3]; |
|
if(sum3>max3){ |
|
max3=sum3; |
|
} |
|
} |
|
max[2]=max3; |
|
|
|
int max4=0; |
|
int sum4=0; |
|
for(int i=0;(i+4) |
|
sum4=data[i]+data[i+1]+data[i+2]+data[i+3]+data[i+4]; |
|
if(sum4>max4){ |
|
max4=sum4; |
|
} |
|
} |
|
max[3]=max4; |
|
|
|
int max5=0; |
|
int sum5=0; |
|
for(int i=0;(i+5) |
|
sum5=data[i]+data[i+1]+data[i+2]+data[i+3]+data[i+4]+data[i+5]; |
|
if(sum5>max5){ |
|
max5=sum5; |
|
} |
|
} |
|
max[4]=max5; |
|
Arrays.sort(max); |
|
System.out.println(max[4]); |
|
|
|
} |
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
int[] data={1,-2,3,-8,5,1}; |
|
new Y().getNumCount(data); |
|
} |
|
|
|
} |