0
int[] array = { 1, 2, 4, 5 };
for (int element : array) {
    System.out.println(element % 2); // it is calculate
    if (element % 2 == 0) { // but it is not calculate
        element--;
    }
}

System.out.println(Arrays.toString(array));

Does the output need to be [1 1 3 5] like this?

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373

0 Answers0