Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MultidimensionalArrays;
- import java.io.IOException;
- import java.util.Arrays;
- import java.util.Scanner;
- public class ReverseMatrixDiagonals_11 {
- public static void main(String[] args) throws IOException {
- Scanner scanner = new Scanner(System.in);
- int[] dimensions = Arrays.stream(scanner.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt)
- .toArray();
- int rows = dimensions[0], cols = dimensions[1];
- int[][] matrix = new int[rows][cols];
- for (int i = 0; i < rows; i++) {
- matrix[i] = Arrays.stream(scanner.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt)
- .toArray();
- }
- int row = rows - 1;
- int col = cols - 1;
- while (row != -1){
- int r = row;
- int c = col;
- while (c < cols && r >= 0){
- System.out.print(matrix[r--][c++] + " ");
- }
- System.out.println();
- col--;
- if(col == -1){
- col = 0;
- row--;
- }
- }
- }
- private static boolean isInbounds(int row, int col, int [][] matrix) {
- return row < 0 || col < 0 || row > matrix.length - 1 || col > matrix[0].length - 1;
- }
- }
Add Comment
Please, Sign In to add comment