JAVA-二维数组遍历

image

改进代码

image

改进代码

image

最终遍历代码

image

package com.itheima;

public class shuzu06 {
    public static void main(String[] args) {
        int[][] arr={{1,2,3},{4,5,6},{7,8,9}};
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }
    }
}

执行结果
1 2 3 
4 5 6 
7 8 9 

Process finished with exit code 0
posted @ 2022-10-27 22:53  NiceTwocu  阅读(54)  评论(0编辑  收藏  举报