Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int[][] triangle = new int[n][];
- for (int row = 0; row < n; row++) {
- triangle[row] = new int[row + 1];
- triangle[row][0] = 1;
- triangle[row][triangle[row].length - 1] = 1;
- for (int col = 1; col < row; col++) {
- triangle[row][col] = triangle[row - 1][col - 1] + triangle[row - 1][col];
- }
- }
- for (int[] row : triangle) {
- for (int r : row) {
- System.out.print(r + " ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement