romancha

MAtrix

Jan 18th, 2021
533
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = scanner.nextInt();
  7.  
  8.         int[][] array = new int[n][n];
  9.         for (int i = 0; i < array.length; i++) {
  10.             for (int j = 0; j < array[i].length; j++) {
  11.                 array[i][j] = Math.abs(-1 * i + j);
  12.             }
  13.         }
  14.  
  15.         for (int[] innerArray : array) {
  16.             for (int element : innerArray)
  17.                 System.out.print(element + " ");
  18.             System.out.println();
  19.         }
  20.     }
  21. }
  22.  
RAW Paste Data