二维数组的创建及初始化及规范输出
如有错误,请见谅,评论会及时改正,谢谢。
package javabasicJuly5rd;
public class TwoDimensionalArray {
public static void main(String[] args) {
int [][]arr2=new int[][]{{1,32,4,4,5,},{233,131,12,},
{31232,342,4,2,},{2432,324,23},{24,234,2}};//创建二维数组
for (int i = 0; i <=arr2.length-1; i++) {//遍历二维数组的行数
for (int j = 0; j <=arr2[i].length-1; j++) {//遍历二维数组的列数
System.out.print(arr2[i][j]+" ");//每个数组的元素之间的距离一个空格
if(j==arr2[i].length-1){//遍历到每行数组的最后一个进行换行
System.out.println();
}
}
}
}
}