In this tutorial, we will write a reverse alphabet triangle pattern in java. Before that, you may go through the following topic in java.
The program takes a user input for the number of rows to be printed. Then the inverted alphabet pattern is displayed on the screen.
Java Program to display the Reverse Pyramid pattern with Alphabet
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");
for (i = rows; i >= 1; i--)
{
for (j = 1; j <= rows - i; j++)
System.out.print(" ");
for (j = 1; j <= 2 *i - 1; j++)
{
if (j <= i)
System.out.print((char)(char)(j + 64) + " ");
else
System.out.print((char)(char)(2 *i - j + 64) + " ");
}
System.out.println();
}
}
}
Enter the number of rows: 5
Output:
A B C D E D C B A
A B C D C B A
A B C B A
A B A
A
