1. Given: int size = 4; int [] [] table = new int[size][size]; a. What is the output after executing the following Java statements? for(int row = 0; row < table.length; row++){ for(int col = 0; col < table[row].length; col++){ System.out.print(table[row][col] + " "); } System.out.println(); } b. What is the output after executing the following Java statements? for(int row = 0; row < table.length; row++){ for(int col = 0; col < table[row].length; col++){ table[row][col] = row * col; System.out.print(table[row][col] + " "); } System.out.println(); } 2. Given: int[][] matrix = { {1, 2, 3}, {4, 5, 6, 7}, {8, 9} }; What is the output after executing the following Java statements? System.out.println("The matrix consist of " + matrix.length + " rows"); for(int row = 0; row < matrix.length; row++){ System.out.println("The length of row " + row + " is " + matrix[row].length); }
1. Given:
int size = 4;
int [] [] table = new int[size][size];
a. What is the output after executing the following Java statements?
for(int row = 0; row < table.length; row++){
for(int col = 0; col < table[row].length; col++){
System.out.print(table[row][col] + " ");
}
System.out.println();
}
b. What is the output after executing the following Java statements?
for(int row = 0; row < table.length; row++){
for(int col = 0; col < table[row].length; col++){
table[row][col] = row * col;
System.out.print(table[row][col] + " ");
}
System.out.println();
}
2. Given:
int[][] matrix = { {1, 2, 3},
{4, 5, 6, 7},
{8, 9} };
What is the output after executing the following Java statements?
System.out.println("The matrix consist of " + matrix.length
+ " rows");
for(int row = 0; row < matrix.length; row++){
System.out.println("The length of row " + row + " is "
+ matrix[row].length);
}
Step by step
Solved in 2 steps