Java Program to Print Fibonacci Triangle



Java Program to Print Fibonacci Triangle :

Sample Code

import java.util.Scanner;

public class fibonnacci {
  public static void main(String[] args) {
    int a = 0, b = 1, i, c, n, j;
    System.out.println("Enter the number of line: ");
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    for (i = 1; i <= n; i++) {
      a = 0;
      b = 1;
      System.out.print(b + " ");
      for (j = 1; j < i; j++) {
        c = a + b;
        System.out.print(c + " ");
        a = b;
        b = c;
      }
      System.out.println(" ");
    }
  }
}

Output

Enter the number of line: 5
1  
1 1  
1 1 2  
1 1 2 3  
1 1 2 3 5

Related Searches to Java Program to print fibonacci triangle