二维数组的遍历

遍历思想:首先使用循环遍历出二维数组中存储的每个一维数组,然后针对每个遍历到的一维数组使用循环遍历该一维数组中的元素

 

package ren.redface.demo;

/**
 * 
 * <p>Title: ArrayDemo.java</p>    
 * <p>Company: www.redface.ren</p>  
 * @author Alec Zhang  
 * @date 2020年4月12日
 */
public class ArrayDemo {
    
    public static void main(String[] args) {
        
        int[][] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
        
        for(int y=0; y<arr.length; y++) {
            for (int x = 0; x < arr[y].length; x++) {
                System.out.print(arr[y][x] + "  ");
            }
            System.out.println();
        }

    }
}

 

posted @ 2020-04-12 17:54  牧牛人Alec  阅读(330)  评论(0编辑  收藏  举报