In this tutorial, we will write a java program to display the reverse right triangle pattern using the alphabet. These are character pattern programs in java. Before that, you may go through the following topic in java.
The programs below take the user input from the user for the number of rows and display the reverse right triangle character pattern in various character orders.
This program can also be called the inverted half pyramid in java or Floyd’s triangle alphabet pattern in java.
Reverse right angled triangle pattern
In this program, the decrement of the Alphabet starts from the right corner of the pattern.
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 | import java.util.Scanner; public class Main { public static void main(String args[]) { int rows, i, j; int ch = 64; Scanner sc = new Scanner(System.in); System.out.print("Enter the number of rows: "); rows = sc.nextInt(); System.out.print("Output:\n\n"); for (i = rows; i >= 1; i--) { for (j = 1; j <= i; j++) { System.out.print((char)(j + ch)); } System.out.println(); } } } |
Output:
Enter the number of rows: 6
Output:
ABCDEF
ABCDE
ABCD
ABC
AB
A