Accenture Java Programming Practice Question
What will be the content of array variable table after executing the following code? public class Trial { public static void main(String[] args) { int []table[]=new int[5][5]; for(int i = 0; i < 3; i++) { for(int j = 0; j < 3; j++) { if(j == i) { table[i][j] = 1; System.out.print(table[i][j]); } else { table[i][j] = 0; System.out.print(table[i][j]); } } System.out.println("\n"); } } }Answer options
A
100
010
001
B
Compilation error
C
111
111
111
D
000
000
000
Correct answer: 100 010 001
Explanation
The two-dimensional int array declaration is valid. The nested loop sets diagonal cells to 1 and other visited cells to 0, printing a 3x3 identity pattern.