Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.IOException;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int size = Integer.parseInt(scanner.nextLine());
- int[][] matrix = new int[size][];
- for (int i = 0; i < size; i++) {
- matrix[i] = Arrays.stream(scanner.nextLine().split(" "))
- .mapToInt(Integer::parseInt)
- .toArray();
- }
- int row = 0;
- int col = 0;
- while (row < size && col < size) {
- int element = matrix[row][col];
- System.out.print(element + " ");// това е за първия диагонал
- row++;
- col++;
- }
- System.out.println();
- //за втория диагонал:
- row = size - 1;
- col = 0;
- while (row >= 0 && col < size) {
- int element = matrix[row][col];
- System.out.print(element + " ");
- row--;
- col++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement