package shuzu; public class shuzu1 { public static void main(String[] args) { int[] a= {-1,-2,-4,-8,-4,7,1,-5}; System.out.println(max(a)); } public static int max(int[] array) { int n=array.length; int max=0; int maxsum=array[0]; int m=0; for(int i = 0;i < n;i++) { if (max <= 0) { max = array[i]; }else { max += array[i]; } if (maxsum < max) { maxsum = max; } m++; System.out.println("当前第"+m+"步,其最大值为:"+maxsum); System.out.println("已经检查了"+m+"个数组"); System.out.println("组成该最子数组为"); } return maxsum; } }