desislava_topuzakova

Untitled

Oct 18th, 2022
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. package MultidimensionalArrays;
  2.  
  3. import java.io.IOException;
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6. public class ReverseMatrixDiagonals_11 {
  7.  
  8. public static void main(String[] args) throws IOException {
  9. Scanner scanner = new Scanner(System.in);
  10.  
  11. int[] dimensions = Arrays.stream(scanner.nextLine().split("\\s+"))
  12. .mapToInt(Integer::parseInt)
  13. .toArray();
  14.  
  15. int rows = dimensions[0], cols = dimensions[1];
  16.  
  17. int[][] matrix = new int[rows][cols];
  18.  
  19. for (int i = 0; i < rows; i++) {
  20. matrix[i] = Arrays.stream(scanner.nextLine().split("\\s+"))
  21. .mapToInt(Integer::parseInt)
  22. .toArray();
  23. }
  24. int row = rows - 1;
  25. int col = cols - 1;
  26.  
  27. while (row != -1){
  28. int r = row;
  29. int c = col;
  30. while (c < cols && r >= 0){
  31. System.out.print(matrix[r--][c++] + " ");
  32. }
  33. System.out.println();
  34. col--;
  35. if(col == -1){
  36. col = 0;
  37. row--;
  38. }
  39. }
  40. }
  41.  
  42. private static boolean isInbounds(int row, int col, int [][] matrix) {
  43. return row < 0 || col < 0 || row > matrix.length - 1 || col > matrix[0].length - 1;
  44. }
  45.  
  46. }
Add Comment
Please, Sign In to add comment