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 program below takes the user input from the user for the number of rows and displays 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | 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 no. of rows: "); rows = sc.nextInt(); System.out.print("Output:\n"); for (i = rows; i >= 1; i--) { for (j = i; j >= 1; j--) System.out.print((char)(j + ch)); System.out.println(); } } } |
Output:
Enter the no. of rows: 6
Output:
FEDCBA
EDCBA
DCBA
CBA
BA
A