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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 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(); } } } |
1 2 3 4 5 6 7 | 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 |