gpt4 book ai didi

java - x[row].length,不明白

转载 作者:行者123 更新时间:2023-11-30 03:31:55 24 4
gpt4 key购买 nike

在两年没有编码之后,我最近重新学习了 java,我忘记了为什么我们将 x[row].length 放在第 13-17 行中:

public class apples {
public static void main(String args[]){
int firstarray[][]={{8,9,10,11},{12,13,14,15}};
int secondarray[][]={{30,31,32,33},{43},{4,5,6}};

System.out.println("This is the first array");
display(firstarray);

System.out.println("This is the second array");
display(secondarray);
}

public static void display(int x[][]){
for(int row=0;row<x.length;row++){
for(int column=0;column<x[row].length;column++){
System.out.print(x[row][column]+"\t");
}
System.out.println();
}
}
}

最佳答案

因为它是一个二维数组,所以该行只是获取数组特定维度的大小,这样就不会发生越界异常。在本例中,它告诉您(或循环)二维数组的每一列中有多少个单元格。

关于java - x[row].length,不明白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28823447/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com