Consider the following method. Method
allEven
is intended to return
true
if all elements in array
arr
are even numbers; otherwise, it should return
false
.
public boolean allEven(int[] arr)
{
boolean isEven = /* expression */;
for (int k = 0; k < arr.length; k++)
{
/* loop body */
}
return isEven;
}
Which of the following replacements for /* expression */ and /* loop body */ should be used so that method allEven will work as intended?
A) false if ((arr[k] % 2) == 0) isEven = true;
B) false if ((arr[k] % 2) != 0) isEven = false; else isEven = true;
C) true if ((arr[k] % 2) != 0) isEven = false;
D) true if ((arr[k] % 2) != 0) isEven = false; else isEven = true;
E) true if ((arr[k] % 2) == 0) isEven = false; else isEven = true;