PackageCom.java.lianxi;ImportJava.util.*; Public classLianxi3 { Public Static voidMain (string[] args) {intNum,i,sum=0; Scanner Cin=NewScanner (system.in); System.out.print ("Please enter the length of the array:"); Num=Cin.nextint (); intarray[]=New int[num]; for(i=0;i<num;i++) {Array[i]=Cin.nextint (); } intMax=array[0]; for(i=0;i<num;i++) { if(sum<=0) {sum=Array[i]; } Else{sum=sum+Array[i]; } if(sum>max) {Max=sum; }} System.out.println ("The maximum number of sub-arrays and is:" +max); }}
Max assigns an array to the first element
Sum is initially 0
Sum is then summed up, summed once, compared to Max once,
If the sum increment value is less than 0, then the increment is not continued, the current element is assigned to Sum,sum.
Until the end of the loop.
Max is the sum of the largest sub-arrays
Members: xueqing Lu Yu
Maximum word group sum improvement!