Java Program to Print Triangle of Mirrored Alphabets Pattern

Write a Java program to print triangle of mirrored alphabets pattern using for loop.

package Alphabets;
import java.util.Scanner;

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

This Java pattern example prints the triangle of mirrored alphabets using while loop.

package Alphabets;

import java.util.Scanner;

public class TriangleMirroredAlp2 {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc = new Scanner(System.in);	
		
		System.out.print("Enter Triangle of Mirrored Alphabets Rows = ");
		int rows = sc.nextInt();
		
		System.out.println("Printing Triangle of Mirrored Alphabets Pattern");
		
		int i, j, k, l, alphabet = 65;
		
		i = 0;
		while(i <= rows - 1) 
		{
			j = rows - 1;
			while(j >= i ) 	
			{
				System.out.print(" ");
				j--;
			}
			
			k = 0;
			while(k <= i)
			{
				System.out.print((char)(alphabet + k));
				k++;
			}
			
			l = i - 1;
			while( l >= 0)
			{
				System.out.print((char)(alphabet + l));
				l--;
			}
			System.out.println();
			i++;
		}
	}
}
Enter Triangle of Mirrored Alphabets Rows = 17
Printing Triangle of Mirrored Alphabets Pattern
                 A
                ABA
               ABCBA
              ABCDCBA
             ABCDEDCBA
            ABCDEFEDCBA
           ABCDEFGFEDCBA
          ABCDEFGHGFEDCBA
         ABCDEFGHIHGFEDCBA
        ABCDEFGHIJIHGFEDCBA
       ABCDEFGHIJKJIHGFEDCBA
      ABCDEFGHIJKLKJIHGFEDCBA
     ABCDEFGHIJKLMLKJIHGFEDCBA
    ABCDEFGHIJKLMNMLKJIHGFEDCBA
   ABCDEFGHIJKLMNONMLKJIHGFEDCBA
  ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
 ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA

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.