View difference between Paste ID: xBAi5qdU and F2QLtdr4
SHOW: | | - or go back to the newest paste.
1
package lection03;
2
3
import java.util.Scanner;
4
5
public class ME02PascalTriangle {
6
    public static void main(String[] args) {
7
        Scanner scanner = new Scanner(System.in);
8
9
        int numRows = Integer.parseInt(scanner.nextLine());
10
        int[] prevRow = {0, 1, 0};
11
        System.out.println("1");
12
        for (int i = 0; i < numRows-1; i++) {
13
            int[] currentRow = new int[prevRow.length + 1];
14
            for (int j = 1; j < currentRow.length-1; j++) {
15
                currentRow[j] = prevRow[j - 1] + prevRow[j];
16
                System.out.print(currentRow[j] + " ");
17
            }
18
            System.out.println();
19
            prevRow=currentRow;
20
        }
21
    }
22
}