签名:但行好事,莫问前程。
前言
记录一下二维数组的学习。
一、二维数组的初始化
1、动态初始化
public class ArrayTest {
public static void main(String[] args) {
// 二维数组的初始化(动态初始化)
int[][] intArray = new int[3][];
}
}
2、静态初始化
public class ArrayTest {
public static void main(String[] args) {
// 二维数组的初始化(静态初始化)
int[][] intArray = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
}
}
二、二维数组的取值
public class ArrayTest {
public static void main(String[] args) {
// 二维数组的初始化(静态初始化)
int[][] intArray = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
// 遍历二维数组
for (int i = 0; i < intArray.length; i++) {
for (int j = 0; j < intArray[i].length; j++) {
System.out.print(intArray[i][j] + "\t");
}
System.out.println();
}
}
}
效果:
总结
博客主要记录了二维数组的简单创建以及取值,有啥错误或不足地方请指正,如果对你有所帮助,请一键三连。