多维数组的建立及遍历
package com.test; import java.util.*; import static java.util.Arrays.fill; public class Main { public static void main(String[] args) { final int MAX = 10; int [][] a = new int[MAX][MAX]; for(int i = 1; i <= 9; i ++){ for(int j = 1; j <= i; j ++){ // Scanner num = new Scanner(System.in); // int digit = num.nextInt(); a[i][j] = j; } } // for(int []i : a){//多维数组中foreach语句的用法 // for(int j : i){ // System.out.println(j); // } // } for(int i = 1; i <= 9; i ++){ for(int j = 1; j <= i; j ++){ System.out.print(a[i][j] + " "); } System.out.println(); } // System.out.println(Arrays.deepToString(a));//区别于遍历一维数组的ToString方法 } }
本文来自博客园,作者:弈星,转载请注明原文链接:https://www.cnblogs.com/8023yyl/p/17099887.html