2020.8.18第四十三天

例5.4二维数组

 1 public class cjava {
 2     public static void main(String[] args) {
 3         int i,j;
 4         int[][] a={{1,2,3},{4,5,6}};
 5         int[][] b=new int[3][2];
 6         System.out.println("array a:");
 7         for(i=0;i<=1;i++)
 8         {
 9         for(j=0;j<=2;j++)
10         {
11          System.out.print(a[i][j]+" ");
12          b[j][i]=a[i][j];
13          }
14         System.out.println();
15         }
16         System.out.println("array b: ");
17         for(i=0;i<=2;i++)
18         {
19             for(j=0;j<=1;j++)
20             {
21             System.out.print(b[i][j]+" ");
22         }
23             System.out.println();    
24     }
25     }
26 }

 

 例5.5 3*4矩阵求最大值

 1 public class cjava {
 2     public static void main(String[] args) {
 3         int[][] a= {{11,32,45,67},{22,44,66,88},{15,72,43,37}};
 4         System.out.println("max value is:"+max_value(a));
 5     }
 6     static int max_value(int array[][])
 7     {
 8         int i,j,max;
 9         max=array[0][0];
10         for(i=0;i<3;i++)
11         {
12             for(j=0;j<4;j++)
13             {
14                 if(array[i][j]>max) max=array[i][j];
15             }
16         }
17         return max;
18     }
19 }

 

 例5.6  输出钻石

 1 public class cjava {
 2     public static void main(String[] args) {
 3         char [][] a= {{' ',' ','*'},{' ','*',' ','*'},{'*',' ',' ',' ','*'},{' ','*',' ','*'},{' ',' ','*'}};
 4         int i,j;
 5         for(i=0;i<a.length;i++)
 6         {
 7             for(j=0;j<a.length;j++)
 8             {
 9                 System.out.print(a[i][j]);
10             }
11             System.out.println();
12     }
13     }
14 }

 

 

2.遇到的问题:不知道为什么最后一个在用i<5会提示越界

3.明天继续例题

posted @ 2020-08-18 21:58  敲敲代代码码  阅读(113)  评论(0编辑  收藏  举报