title: Triangle pattern in Java
body: <p>I am creating a triangle in Java with a specific number pattern. I am having problems coming up with a mathematical equation that outputs these numbers/pattern once the user enters the number of lines:<br>
  <a href="https://i.stack.imgur.com/Wh8hy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Wh8hy.png" alt="SEE IMAGE"></a> </p>
  
  <p>My code works fine but the numbers are not correct. Does anyone know an equation for that pattern? </p>
  
  <p>My code:</p>
  
  <pre><code>import java.util.Scanner;
  public class Triangle {
  
      public static void main(String[] args) {
          Scanner input = new Scanner (System.in);
          System.out.println("Enter the number of lines: ");
          int rows = input.nextInt();
  
          for(int i =0;i&lt;rows;i++) {
              int number = 1;
              System.out.format("%"+(rows-i)*2+"s","");
              for(int j=0;j&lt;=i;j++) {
                  System.out.format("%4d",number);
                  number = number * (i - j) / (j + 1);
  
              }
              System.out.println();
          }
      }
  }
  </code></pre>