Inverted Right-Angled Alphabet Triangle in Java

What You’ll Learn
Print an inverted alphabet triangle: the first row is the longest (ABCDE for 5 rows), then each next row drops one letter while still starting from A.
This is the partner to program 1 (growing rows). The inner loop stays the same idea; only the outer loop direction changes.
⭐ Pattern Output
When you run the program with rows = 5:
ABCDE
ABCD
ABC
AB
AComplete Java Program
Fixed rows = 5 version. The outer loop counts down to reduce width; the inner loop prints from A upward.
public class Main {
public static void main(String[] args) {
int rows = 5;
for (int i = rows; i >= 1; i--) {
char ch = 'A';
for (int j = 1; j <= i; j++) {
System.out.print(ch++);
}
System.out.println();
}
}
}🧠 How It Works
Outer loop shrinks the row
i goes from rows down to 1, so row lengths are rows, rows-1, ... , 1.
Reset to A each row
Set ch = 'A' at the start of every row so each line begins from A.
Print i letters with ch++
for (int j = 1; j <= i; j++) runs i times. System.out.print(ch++) prints the current letter then advances to the next code unit, so each row is a fresh forward run from 'A'.
End row, shorter next
System.out.println() ends the line; the outer loop decreases i, so the next row prints one fewer character — the inverted triangle.
Inverted triangle
n(n + 1)/2 characters total — O(n²) time, O(1) extra space. The outer index shrinks from rows to 1 while each row still starts fresh at 'A'.
Variation — User Input Version
Accept rows with Scanner and clamp to 26 (A to Z):
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));
for (int i = rows; i >= 1; i--) {
char ch = 'A';
for (int j = 1; j <= i; j++) {
System.out.print(ch++);
}
System.out.println();
}
sc.close();
}
}💡 Tips for Enhancement
Try These
- Switch the outer loop to count up to get the growing triangle again (Program 1)
- Start from
'a'for lowercase output - Right-align the output with leading spaces
- Try printing numbers instead of letters
Avoid
- Forgetting to reset
cheach row if you want every line to start from A - Allowing
rowsto exceed 26 without handling wrap-around - Mixing up the loop direction when you want an inverted shape
Key Takeaways
Counting i down from rows to 1 creates the inverted shape.
Reset to 'A' each row to keep each line starting from A.
Total printed characters are n(n+1)/2, so runtime is O(n²).
This is the inverted counterpart of the growing alphabet triangle.
❓ Frequently Asked Questions
rows. This program starts with rows letters and decreases to 1.n rows.Next: Java Alphabet Pattern 6
Continue to Program 6 for the next alphabet pattern in Java.
You can turn the growing triangle into an inverted triangle by only reversing the outer loop direction—the inner loop stays almost identical.
10 people found this page helpful
