void max(int[] x){
int maxendinghere=0;
int maxsofar=0;
int l=0,u=0;//新数组的下界与上界
for (int j = 0; j < x.length; j++) {
if(maxendinghere+x[j]>0){
maxendinghere=maxendinghere+x[j];
}else{
l=j+1;
maxendinghere=0;
}
if(maxsofar<maxendinghere){
maxsofar=maxendinghere;
u=j;
}
}
System.out.println(l);
System.out.println(u);
}
参考编程珠玑,并修改