每周总结之第四周

这一周,建民哥给我们讲述了怎么使得代码可以变得简洁,方便阅读,

我还对上周进行的测试进行了第二阶段成功测试,

package qiuhe;

public class qiuhe {
 public static void main(String args[]) {  

        // TODO Auto-generated method stub
         int matrix[][]={{1000000000,-2000000000,300001560},{-4,1051010101,6},{-7,800000000,-9}};
            maxSum(matrix);

    }
 public static void maxSum(int matrix[][])
     {
         if(matrix==null||matrix.length==0)
             return;
         int max=0;
         int col=matrix[0].length,row=matrix.length;     
         for(int i=0;i<row;i++)
         {
             int arr[]=new int[col];
             for(int j=i;j<row;j++)
             {
             //遍历所有的子行
                 for(int k=0;k<col;k++)
                 {
                     arr[k]+=matrix[j][k];
                     //将每子行的值进行相加然后利用子数组的最大和就可以求出子矩阵的最大和
                 }
                 for(int l=0;l<col;l++) {
                  if((l+1)%3==0) {
                  System.out.println();
                  }
                 }
                 max=Math.max(max(arr), max);
                 //求出数组的子数组和最大值
             }
         }
         System.out.println("最后得到的最大值为:"+max);
     }
     public static int max(int arr[])//求最大子数组之和
     {
         int max=0,sum=0;
         for(int i=0;i<arr.length;i++)
         {
             if(sum<=0)
             {
                 sum=arr[i];
             }
             else {
                 sum+=arr[i];
             }
             max=Math.max(sum, max);
         }
         return max;
     }
}

posted @ 2022-06-14 21:21  救救孩子吧/  阅读(16)  评论(0)    收藏  举报