Reverse Alphabet Decreasing Triangle in Java

What You’ll Learn
Print a triangle whose first row is the full reverse run from E to A, then each row drops the leftmost letter: EDCBA, DCBA, CBA, BA, A.
This pairs well with program 6 (ABCDE, BCDE, ...). Here everything moves toward A instead.
⭐ Pattern Output
When you run the program with rows = 5:
EDCBA
DCBA
CBA
BA
AComplete Java Program
Fixed rows = 5 version. The outer loop sets the row’s starting letter and the inner loop prints down to A.
public class Main {
public static void main(String[] args) {
char high = 'E';
for (char start = high; start >= 'A'; start--) {
for (char ch = start; ch >= 'A'; ch--) {
System.out.print(ch);
}
System.out.println();
}
}
}🧠 How It Works
Outer loop chooses the row start
char high = 'E' anchors the first row. for (char start = high; start >= 'A'; start--) moves the leftmost letter from E down to A.
Inner loop prints down to A
For each row, print letters from start down to 'A' by decrementing the char.
Row length shrinks
Each time start decreases, ch >= 'A' spans one fewer letter, so widths are 5, 4, 3, 2, 1 for the five-row demo.
Newline per row
System.out.println() after the inner loop keeps each descending run on its own line. Generalize with high = (char)('A' + rows - 1) as in the Scanner example.
Total work
n(n + 1)/2 prints — O(n²) time, O(1) extra space. Each row is a contiguous reverse suffix from a moving peak down to 'A'.
Variation — User Input Version
Compute the top letter as high = (char)('A' + rows - 1) and then print down to A:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of rows (max 26): ");
int rows = sc.nextInt();
rows = Math.max(1, Math.min(rows, 26));
char high = (char) ('A' + rows - 1);
for (char start = high; start >= 'A'; start--) {
for (char ch = start; ch >= 'A'; ch--) {
System.out.print(ch);
}
System.out.println();
}
sc.close();
}
}💡 Tips for Enhancement
Try These
- Use lowercase letters by switching to
'a'as the base - Compare with program 2 to see what happens when you reset the start letter each row
- Try printing with spaces for a right-aligned version
- Replace letters with numbers to practice the same loop idea
Avoid
- Letting
rowsexceed 26 without handling wrap-around - Using
++loops when you want reverse alphabetical order - Printing without a newline after each row
Key Takeaways
Outer loop controls the row’s starting letter (E, D, C, ...).
Inner loop prints from the row start down to A.
Row lengths shrink by one each line: n, n-1, ..., 1.
Total printed characters are n(n+1)/2, so runtime is O(n²).
❓ Frequently Asked Questions
'A', so the last printed character is always A.n rows.Next: Java Alphabet Pattern 8
Continue to Program 8 for the next alphabet pattern in Java.
This pattern is symmetric to Program 6: Program 6 keeps the right edge fixed at E; Program 7 keeps the right edge fixed at A.
10 people found this page helpful
