What will be the output of the following code? -------------------- public static void main(String[] args) { int[][] matrix = new int[][] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; int rows = matrix.length, cols = matrix[0].length; int[][] ans = new int[cols][rows]; for (int r = 0; r < rows - 1; ++r) { for (int c = 0; c < cols - 1; ++c) { ans[c][r] = matrix[r][c]; } } System.out.println(Arrays.deepToString(ans)); }
Geekific
What will be the output of the following code?
--------------------
public static void main(String[] args) {
int[][] matrix = new int[][] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int rows = matrix.length, cols = matrix[0].length;
int[][] ans = new int[cols][rows];
for (int r = 0; r < rows - 1; ++r) {
for (int c = 0; c < cols - 1; ++c) {
ans[c][r] = matrix[r][c];
}
}
System.out.println(Arrays.deepToString(ans));
}
3 weeks ago | [YT] | 6