Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.Arrays;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int[] matrixSize = Arrays.stream(scan.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt).toArray();
- int[][] matrix = new int[matrixSize[0]][matrixSize[1]];
- for (int i = 0; i < matrix.length; i++) {
- int[] nums = Arrays.stream(scan.nextLine().split("\\s+"))
- .mapToInt(Integer::parseInt).toArray();
- for (int j = 0; j < matrix[i].length; j++) {
- matrix[i][j] = nums[j];
- }
- }
- int row = matrix.length - 1;
- int col = matrix[0].length - 1;
- while (true){
- int i = 0;
- while (true) {
- try {
- System.out.print(matrix[row - i][col + i] + " ");
- i++;
- } catch (Exception e) {
- break;
- }
- }
- if (col == 0 && row > 0){
- row -= 1;
- } else if (col <= 0 && row == 0){
- break;
- } else {
- col--;
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement