[英]Java Code Tracing of Arrays
I'm having trouble with this school work, you have to trace the code of this array using a tracing table, however I am stuck for an answer. 我在这项功课上遇到了麻烦,您必须使用跟踪表来跟踪此数组的代码,但是我一直在寻找答案。
When I go through the code I get to the line where data[i]
is given the index position of 0, which is 50
. 当我遍历代码时,到达data[i]
的索引位置为0,即50
。 I then get confused as to if the table stops on that line because it cannot proceed because of data[i]
is not less than data.length
. 然后,我对表是否在该行上停止感到困惑,因为由于data[i]
不小于data.length
导致它无法继续进行。 So does it end there or am I wrong? 到此为止还是我错了?
public static int ???(int[] data) {
int result = 1000;
for (int i = 0; i < data.length; i++) {
if (data[i] < result) {
result = data[i];
}
}
return result;
}
and the data is 数据是
{ 50, 43, 22, 30 } {50,43,22,30}
After the test, what do you think below line of code do? 测试之后,您如何看待下面的代码行?
result = data[i]; 结果=数据[i];
for (int i = 0; i < data.length; i++)
您将i
与data.length
进行比较,而不将data[i]
与data.length
进行比较,以便您的循环按预期运行(即,不会以i = 0结束)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.