Design ideas:
1, by invoking the input function for array input;
2, using the classroom Teacher's dynamic planning of the array of sub-arrays to find the maximum operation;
* 3, add a max0 to the maximum value of the storage, to avoid the maximum occurrence of the middle of the array caused by the missing problem;
Problems that arise:
Long time no eclipse, a lot of basic operations also need to review to be able;
Digital input code through the Internet query to knock good;
Possible solutions:
Other methods that are currently not expected to be within the allowable range of time complexity;
Source:
Package Max;import java.util.*; Public classArray_max { Public Static intCin (inti) {Scannerinch=NewScanner (System.inch); System. out. println ("Please enter section"+ (i+1)+"number"); intb=inch. Nextint (); returnb; } Public Static intGet (intLen[],intnum) { intmax = len[0]; intmax0=0; for(intI=1; i<num;i++){ if(len[i]>0) {Max=max+Len[i]; } Else{ if(max>max0) {max0=Max; } Max=0; } } returnmax0; } Public Static voidMain (String args[]) {Scannerinch=NewScanner (System.inch); System. out. println ("Please enter the number of array numbers:"); intnum=inch. Nextint (); intlen[]=New int[num]; for(intI=0; i<num;i++) {Len[i]=Cin (i); } intmax=Get (Len,num); System. out. Print ("the maximum number of sub-arrays and is:"+max); }}
Results:
Summary: In fact, the code is very simple, the key is the thought is very difficult to think, if there is no class teacher to mention, estimated that only thinking will cost a lot of time!
Week five Classroom Test