二维数组相关问题
public class YangHuiTest {public static void main(String[] args) {
//1.声明并初始化二维数组
int[][] yangHui = new int[];
//2.给数组的元素赋值
for(int i = 0;i < yangHui.length;i++){
yangHui = new int;
//2.1 给首末元素赋值
yangHui = yangHui = 1;
//2.2 给每行的非首末元素赋值
//if(i > 1){
for(int j = 1;j < yangHui.length - 1;j++){
yangHui = yangHui + yangHui;
}
//}
}
//3.遍历二维数组
for(int i = 0;i < yangHui.length;i++){
for(int j = 0;j < yangHui.length;j++){
System.out.print(yangHui + "");
}
System.out.println();
}
}
}
代码如上,我想知道下面这里
for(int j = 1;j < yangHui.length - 1;j++){
yangHui = yangHui + yangHui;
二维数组行数没有规定,这里yangHui.length - 1是怎么获得的呢? public class Main {
public static void main(String[] args) {
//1.声明并初始化二维数组
int[][] yangHui = new int[];
//2.给数组的元素赋值
for (int i = 0; i < yangHui.length; i++) {
yangHui = new int; // <----- 注意这里 -----
System.out.print("长度:" + yangHui.length + "\n"); // <----- 打印看看便知道了 -----
//2.1 给首末元素赋值
yangHui = yangHui = 1;
//2.2 给每行的非首末元素赋值
//if(i > 1){
for (int j = 1; j < yangHui.length - 1; j++) {
yangHui = yangHui + yangHui;
}
//}
}
//3.遍历二维数组
for (int i = 0; i < yangHui.length; i++) {
for (int j = 0; j < yangHui.length; j++) {
System.out.print(yangHui + "");
}
System.out.println();
}
}
} 傻眼貓咪 发表于 2022-2-12 18:09
懂了,,是我梦游了{:10_243:} {:10_254:}{:10_254:}{:10_254:}
页:
[1]