MadCortez

Untitled

Sep 30th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2. class MyClass {
  3.     public static void main(String[] args){
  4.         final int MIN_SIZE = 0;
  5.         final int MAX_SIZE = 21;
  6.         boolean isNotValid = true;
  7.         int n;
  8.         int temp;
  9.         System.out.println("Данная программа строит n строк треугольника Паскаля");
  10.         System.out.print("Введите число n в диапазоне " + (MIN_SIZE + 1) + ".." + (MAX_SIZE - 1) + ": ");
  11.         Scanner in = new Scanner(System.in);
  12.         do {
  13.             n = Integer.parseInt(in.nextLine());
  14.                 if (n > MIN_SIZE && n < MAX_SIZE)
  15.                     isNotValid = false;
  16.                 else
  17.                     System.out.println("Введите число n в заданном диапазоне");
  18.         } while (isNotValid);
  19.         int a[][] = new int[n][n];
  20.         System.out.println(n + " строк треугольника Паскаля: ");
  21.         for (int i = 0; i < n; i++) {
  22.             a[i][0] = 1;
  23.             a[i][i] = 1;
  24.             for (int j = 1; j < i; j++)
  25.                 a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
  26.             for (int j = 0; j <= i; j++)
  27.                 System.out.print(a[i][j] + " ");
  28.             System.out.println();
  29.         }
  30.     }
  31. }
  32.  
Add Comment
Please, Sign In to add comment