Java Program to Print Pascal Triangle

« Previous Program Next Program »

Print Pascal Triangle

To print pascal triangle in Java Programming, you have to use three for loops and start printing pascal triangle as shown in the following example.

Java Programming Code to Print Pascal Triangle

Following Java Program ask to the user to enter the number of line/row upto which the Pascal triangle will be printed to print the Pascal triangle on the screen:

/* Java Program Example - Print Pascal Triangle */
import java.util.Scanner;

public class JavaPascalTriangle
    public static void main(String args[])
       int r, i, k, number=1, j;
      Scanner scan = new Scanner(;
      System.out.print("Enter Number of Rows : ");
      r = scan.nextInt();
         for(k=r; k>i; k--)
            System.out.print(" ");
            number = 1;
             System.out.print(number+ " ");
                 number = number * (i - j) / (j + 1);

When the above Java Program is compile and executed, it will produce the following output:

Java Program print pascal triangle

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:

Java Online Test

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.