gpt4 book ai didi

java - 我无法弄清楚这个数组

转载 作者:行者123 更新时间:2023-12-01 09:53:18 25 4
gpt4 key购买 nike

我正在做一些个人工作,并且正在使用我想到的这个数组,但是在代码停止运行后我无法弄清楚该数组是什么。

int cnt = 0; 
int[][] numarray = new int[2][3];
for(int i = 0; i < 3; i++) {
for(int j = 0; j< 2; j++) {
numarray[j][i] = cnt;
cnt++;
}
}

我很确定它以 [2][1] 结尾,但我不是 100% 确定

最佳答案

刚刚尝试了这段代码:

    int cnt = 0; 
int[][] numarray = new int[2][3];
for(int i = 0; i < 3; i++) {
for(int j = 0; j< 2; j++) {
numarray[j][i] = cnt;
cnt++;
System.out.print(numarray[j][i]+" ");
}
System.out.println("");
}

得到了这个结果:

0 1 
2 3
4 5

每次迭代“cnt”都会增加 1。这就是为什么你有 0,1,2,3,4,5。

还学习如何在 IDE 中使用调试器,然后您可以自己探索 i、j、cnt 的值。

关于java - 我无法弄清楚这个数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37451308/

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