Java Program to Print Right Pascals Triangle Alphabets Pattern

Write a Java program to print right pascals triangle alphabets pattern using for loop.

package Alphabets;

import java.util.Scanner;

public class RightPascalTriAlp1 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc = new Scanner(System.in);	
		
		System.out.print("Enter Right Pascal Triangle of Alphabets Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("The Right Pascal Triangle Alphabets Pattern");
		
		int i, j, alphabet = 65;
		
		for (i = 0; i <= rows - 1; i++) 
		{
			for (j = 0; j <= i; j++ ) 	
			{
				System.out.print((char)(alphabet + j) + " ");
			}
			System.out.println();
		}
		
		for (i = rows - 1; i >= 0; i--) 
		{
			for (j = 0; j < i; j++ ) 	
			{
				System.out.print((char)(alphabet + j) + " ");
			}
			System.out.println();
		}
	}
}
Java Program to Print Right Pascals Triangle Alphabets Pattern

This Java program prints the right pascals triangle pattern of alphabets using while loop. For more Alphabet examples, refer to the Java Alphabet Pattern Programs article.

package Alphabets;

import java.util.Scanner;

public class RightPascalTriAlp2 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc = new Scanner(System.in);	
		
		System.out.print("Enter Right Pascal Triangle of Alphabets Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("The Right Pascal Triangle Alphabets Pattern");
		
		int i, j, alphabet = 65;
		i = 0;
		
		while( i <= rows - 1) 
		{
			j = 0;
			while(j <= i ) 	
			{
				System.out.print((char)(alphabet + j) + " ");
				j++;
			}
			System.out.println();
			i++;
		}
		
		i = rows - 1;
		while( i >= 0) 
		{
			j = 0;
			while(j < i) 	
			{
				System.out.print((char)(alphabet + j) + " ");
				j++;
			}
			System.out.println();
			i--;
		}
	}
}
Enter Right Pascal Triangle of Alphabets Rows = 13
The Right Pascal Triangle Alphabets Pattern
A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F 
A B C D E F G 
A B C D E F G H 
A B C D E F G H I 
A B C D E F G H I J 
A B C D E F G H I J K 
A B C D E F G H I J K L 
A B C D E F G H I J K L M 
A B C D E F G H I J K L 
A B C D E F G H I J K 
A B C D E F G H I J 
A B C D E F G H I 
A B C D E F G H 
A B C D E F G 
A B C D E F 
A B C D E 
A B C D 
A B C 
A B 
A 

This Java example uses the Java do while loop to display the right pascals triangle of alphabets pattern.

package Alphabets;

import java.util.Scanner;

public class RightPascalTriAlp3 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc = new Scanner(System.in);	
		
		System.out.print("Enter Right Pascal Triangle of Alphabets Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("The Right Pascal Triangle Alphabets Pattern");
		
		int i, j, alphabet = 65;
		i = 0;
		
		do 
		{
			j = 0;
			do 	
			{
				System.out.print((char)(alphabet + j) + " ");

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

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

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

		} while(--i >= 0);
	}
}
Enter Right Pascal Triangle of Alphabets Rows = 15
The Right Pascal Triangle Alphabets Pattern
A 
A B 
A B C 
A B C D 
A B C D E 
A B C D E F 
A B C D E F G 
A B C D E F G H 
A B C D E F G H I 
A B C D E F G H I J 
A B C D E F G H I J K 
A B C D E F G H I J K L 
A B C D E F G H I J K L M 
A B C D E F G H I J K L M N 
A B C D E F G H I J K L M N O 
A B C D E F G H I J K L M N 
A B C D E F G H I J K L M 
A B C D E F G H I J K L 
A B C D E F G H I J K 
A B C D E F G H I J 
A B C D E F G H I 
A B C D E F G H 
A B C D E F G 
A B C D E F 
A B C D E 
A B C D 
A B C 
A B 
A 
A 

Also Read