pascal 27s triangle in java using recursion

Solutions on MaxInterview for pascal 27s triangle in java using recursion by the best coders in the world

showing results for - "pascal 27s triangle in java using recursion"
Giovanni
05 Mar 2019
1// Pascal's triangle in java using recursion
2import java.util.Scanner;
3public class RecursionPascalTriangle 
4{
5   public static void display(int num)
6   {
7      for(int a = 0; a < num; a++)
8      {
9         for(int b = 0; b <= a; b++)
10         {
11            System.out.println(pascalTriangle(a, b) + " ");
12         }
13         System.out.println();
14      }
15   }
16   public static int pascalTriangle(int a, int b)
17   {
18      if(b == 0 || b == a)
19      {
20         return 1;
21      }
22      else
23      {
24         return pascalTriangle(a - 1, b - 1) + pascalTriangle(a - 1, b);
25      }
26   }
27   public static void main(String[] args)
28   {
29      Scanner sc = new Scanner(System.in);
30      System.out.println("Please enter number of rows: ");
31      int row = sc.nextInt();
32      display(row);
33      sc.close();
34   }
35}