package day05;
public class ArrayLengthDemo {
public static void main(String[] args){
// 新建一个不规则数组
int[][] arr ={
{1,2},
{3,4,5},
{6}
};
// 打印二维数组的行数
System.out.println(arr.length);
// 打印每一行对应的列数 行下标对应的范围是0 -> arr.length - 1
System.out.println(arr[0].length);
System.out.println(arr[1].length);
System.out.println(arr[2].length);
// 两层for循环遍历二维数组
//i表示行
for(int i = 0; i < arr[i].length; i++){
// i = 0时 第1行 j 表示每一行对应的列
for(int j =0; j < arr[i].length;j++){
// 打印二维数组的 第i行 第j列的值
System.out.println(arr[i][j]+" ");
}
System.out.println();
}
}
}
12-21
09-25
684
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-24
5523
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交