且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

根据数字是否为偶数(真)(假)将int []转换为boolean []

更新时间: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;