Alphabet Pyramid Pattern in Java: pattern 2

In this tutorial, we will write a Java program to display alphabet pyramid patterns. Before that, you may go through the following topic in java.

Trianglular alphabet pattern

This is a program the right half and left half remain exactly the same on each row forming a triangular pyramid.

import java.util.Scanner;

public class Main
{
  public static void main(String args[])
  {
    int rows, i, j;
    Scanner scan = new Scanner(System.in);

    System.out.print("Enter the number of rows: ");
    rows = scan.nextInt();

    System.out.print("Output:\n\n");
    for (i = 1; i <= rows; i++)
    {
      for (j = 1; j <= rows - i; j++)
        System.out.print(" ");

      //left half
      for (j = i; j > 0; j--)
        System.out.print((char)(j + 64));

      //right half
      for (j = 2; j <= i; j++)
        System.out.print((char)(j + 64));

      System.out.println();
    }
  }
}

Output:

Enter the number of rows: 8
Output:
     
       A
      BAB
     CBABC
    DCBABCD 
   EDCBABCDE
  FEDCBABCDEF
 GFEDCBABCDEFG
HGFEDCBABCDEFGH