更新时间:2023-11-26 09:23:34
在您的循环中,i
是元素的 value ,而不是元素的 index ,因此可能不是有效的索引.
In your loop, i
is the element’s value, not its index, and so is likely to not be a valid index.
将您的 foreach 循环更改为常规的for
循环:
Change your foreach loop to a conventional for
loop:
boolean[] result = new boolean[array.length];
for (int i = 0; i < array.length; i++) {
result[i] = array[i]%2==0;
}
return result;