public class Test { public static void main(String[] args) { int[][] values = { {9, 8, 7, 6, 5}, {7, 6, 5, 4, 3}, {4, 3, 2, 1, 0}, {4, 3, 2, 1, 0}}; for (int i = 0; i < values.length; i++) { for (int j = i; j < values[i].length; j++) { System.out.print(values[i][j] - values[i+2][j+2]); } System.out.println(); } } }

Respuesta :

Answer:

The program will output 777 and throw an error of ArrayIndexOutOfBoundsException.

Explanation:

The program declare an array called values. It is a multidimensional array. It then try to loops through the array and do some computation.

It has a nested for loop for going through the array.

For the first for-loop the length is 4.

During the computation in the inner loop; Exception thrown is: ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5

The exception is thrown because when i is 3, then values[i+2][j+2] will be values[5][5] and the length of values is 4.

ACCESS MORE
EDU ACCESS