title: Pascal's Triangle Recursion Java
body: <p>I'm trying to make program that will calculate Pascal's triangle and I was looking up some examples and I found this one. But I don't really understand how the pascal method works. But everything else makes sense. </p>
  
  <pre><code>import java.util.Scanner;
  public class Pascal {
    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      System.out.print("Enter the number of rows to print: ");
      int rows = scanner.nextInt();
      System.out.println("Pascal Triangle:");
      print(rows);
      scanner.close();
    }
  
    public static void print(int n) {
      for (int i = 0; i &lt; n; i++) {
        for (int j = 0; j &lt;= i; j++) {
          System.out.print(pascal(i, j) + " ");
        }
        System.out.println();
      }
    }
  
    public static int pascal(int i, int j) {
      if (j == 0 || j == i) {
        return 1;
      } else {
        return pascal(i - 1, j - 1) + pascal(i - 1, j);
      }
    }
  }
  </code></pre>