Java Program to Print Left Pascals Number Triangle

Write a Java program to print left pascals number triangle using for loop.

import java.util.Scanner;

public class LeftPascalNumber1 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		int i, j, k;
		
		System.out.print("Enter Left Pascals Number Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Left Pascals Triangle Number Pattern");
		
		for (i = 1 ; i <= rows; i++ ) 
		{
			for (j = i ; j < rows; j++ ) 
			{
				System.out.print("  ");
			}
			for(k = 1; k <= i; k++) 
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
		
		for (i = rows; i >= 1; i-- ) 
		{
			for (j = i ; j <= rows; j++ ) 
			{
				System.out.print("  ");
			}
			for(k = 1; k < i; k++) 
			{
				System.out.print(k + " ");
			}
			System.out.println();
		}
	}
}
Java Program to Print Left Pascals Number Triangle

This Java example displays the left pascal triangle number pattern using a while loop.

import java.util.Scanner;

public class LeftPascalNumber2 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Left Pascals Number Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Left Pascals Triangle Number Pattern");
		int i = 1, j, k;
		
		while (i <= rows ) 
		{
			
			j = i ;
			while ( j < rows ) 
			{
				System.out.print("  ");
				j++;
			}
			
			k = 1;
			while( k <= i) 
			{
				System.out.print(k + " ");
				k++;
			}
			System.out.println();
			i++;
		}
		
		i = rows; 
		while (i >= 1) 
		{
			
			j = i ;
			while (j <= rows) 
			{
				System.out.print("  ");
				j++;
			}
			
			k = 1;
			while( k < i) 
			{
				System.out.print(k + " ");
				k++;
			}
			System.out.println();
			i--;
		}
	}
}
Enter Left Pascals Number Triangle Pattern Rows = 7
Printing Left Pascals Triangle Number Pattern
            1 
          1 2 
        1 2 3 
      1 2 3 4 
    1 2 3 4 5 
  1 2 3 4 5 6 
1 2 3 4 5 6 7 
  1 2 3 4 5 6 
    1 2 3 4 5 
      1 2 3 4 
        1 2 3 
          1 2 
            1 

Java Program to Print Left Pascals Number Triangle using do while loop.

import java.util.Scanner;

public class LeftPascalNumber3 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Enter Left Pascals Number Triangle Pattern Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Left Pascals Triangle Number Pattern");
		int i = 1, j, k;
		
		do
		{
			
			j = i ;
			do 
			{
				System.out.print("  ");

			} while ( j++ < rows );
			
			k = 1;
			do
			{
				System.out.print(k + " ");

			} while( ++k <= i);
			
			System.out.println();

		} while (++i <= rows );
		
		i = rows; 
		do
		{
			
			j = i - 1;
			do
			{
				System.out.print("  ");

			} while (++j <= rows);
			
			k = 1;
			do
			{
				System.out.print(k + " ");

			} while( ++k < i);
			
			System.out.println();

		} while (--i > 1) ;
	}
}
Enter Left Pascals Number Triangle Pattern Rows = 9
Printing Left Pascals Triangle Number Pattern
                  1 
                1 2 
              1 2 3 
            1 2 3 4 
          1 2 3 4 5 
        1 2 3 4 5 6 
      1 2 3 4 5 6 7 
    1 2 3 4 5 6 7 8 
  1 2 3 4 5 6 7 8 9 
    1 2 3 4 5 6 7 8 
      1 2 3 4 5 6 7 
        1 2 3 4 5 6 
          1 2 3 4 5 
            1 2 3 4 
              1 2 3 
                1 2 
                  1 

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.