Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class MyClass {
- public static void main(String[] args){
- final int MIN_SIZE = 0;
- final int MAX_SIZE = 21;
- boolean isNotValid = true;
- int n;
- int temp;
- System.out.println("Данная программа строит n строк треугольника Паскаля");
- System.out.print("Введите число n в диапазоне " + (MIN_SIZE + 1) + ".." + (MAX_SIZE - 1)
- + ": ");
- Scanner in = new Scanner(System.in);
- do {
- n = Integer.parseInt(in.nextLine());
- if (n > MIN_SIZE && n < MAX_SIZE)
- isNotValid = false;
- else
- System.out.println("Введите число n в заданном диапазоне");
- } while (isNotValid);
- int a[][] = new int[n][n];
- System.out.println(n + " строк треугольника Паскаля: ");
- for (int i = 0; i < n; i++) {
- a[i][0] = 1;
- a[i][i] = 1;
- for (int j = 1; j < i; j++)
- a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
- for (int j = 0; j <= i; j++)
- System.out.print(a[i][j] + " ");
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement