Question #37720

Write a method with a void return value that inverts all the elements of a two-dimensional array of booleans (true becomes false and false becomes true).

Expert's answer

void invert(boolean arr[][]) {

for (int i = 0; i < arr.length; i++) {

for (int j = 0; j < arr[i].length; j++) {

arr[i][j] = !arr[i][j];

}

}

}

for (int i = 0; i < arr.length; i++) {

for (int j = 0; j < arr[i].length; j++) {

arr[i][j] = !arr[i][j];

}

}

}

## Comments

## Leave a comment