Advertisement
Guest User

Untitled

a guest
Mar 15th, 2023
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | Source Code | 0 0
  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.         int[][] matrix = new int[n][n];
  8.  
  9.         for (int i = 0; i < n; i++) {
  10.             for (int j = 0; j < n; j++) {
  11.                 if (i == j) {
  12.                     matrix[i][j] = 1;
  13.                 } else if (i > j) {
  14.                     matrix[i][j] = 2;
  15.                 } else {
  16.                     matrix[i][j] = 0;
  17.                 }
  18.             }
  19.         }
  20.  
  21.         for (int i = 0; i < n; i++) {
  22.             for (int j = 0; j < n; j++) {
  23.                 System.out.print(matrix[i][j] + " ");
  24.             }
  25.             System.out.println();
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement