A reverse decreasing alphabet triangle prints each row backward down to A, while the starting letter moves one step closer to A on every line.
Remember
Rule: on row with start i, print i..A (descending)
EDCBA
DCBA
CBA
BA
A ← 5 rows (top = 'E')
Same shrinking widths as Program 6, but letters run the other way. Compare with Program 8, which always starts at the top letter and shortens the tail instead.
Approach
How to Solve It
Two ways to emit the same shape — classic nested char loops, or spaced letters for readability.
Method
Idea
Best for
Nested char loops
Outer i-- from top; inner prints i..A
Learning, interviews, exams
Spaced letters
Same bounds; print j + " "
Clearer console demos once loops click
Pseudocode
Pseudocode
top = 'A' + rows - 1
for i from top down to 'A':
for j from i down to 'A':
print j (no newline)
print newline
Cheat sheet
Goal
Pattern
Top letter
char top = (char)('A' + rows - 1);
Shrink start
for (char i = top; i >= 'A'; i--)
Print i..A
for (char j = i; j >= 'A'; j--) System.out.print(j);
End the row
System.out.println();
vs Program 6
Program 6: forward i..end; this page: reverse i..A
Letter total
n + (n−1) + … + 1 = n(n+1)/2
Printing Letters vs Starting a New Line
API
Effect
Use for
System.out.print
Stays on the same line
Each letter
System.out.println
Ends the current line
After the inner loop finishes a row
Print letters without a newline, then end the row once.
Try it
Live Preview
Change the row count and the reverse triangle updates instantly — every row still ends on A.
Whole numbers from 1 to 10. Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · top E · 15 letters
EDCBA
DCBA
CBA
BA
A
Trace
Worked Walkthrough — Top = E (5 rows)
Trace each start letter i and the descending run down to A.
i (start)
Inner range
Printed row
Letters
E
E..A
EDCBA
5
D
D..A
DCBA
4
C
C..A
CBA
3
B
B..A
BA
2
A
A..A
A
1
Total letter prints: 5 + 4 + 3 + 2 + 1 = 15 = 5×6/2. The right edge is always A; that triangular sum is why time is O(n²).
Code
Java Programs
Three complete programs: fixed A–E, row-count input, and a spaced-letter variant. Use View Output to reveal sample results.
Example 1 — Fixed Top E
Hard-coded height — outer loop lowers the start; inner loop always counts down to A.
Java
public class ReverseDecreasingTriangle {
public static void main(String[] args) {
for (char i = 'E'; i >= 'A'; i--) {
for (char j = i; j >= 'A'; j--) {
System.out.print(j);
}
System.out.println();
}
}
}
Output
EDCBA
DCBA
CBA
BA
A
How It Works
1. Outer loop picks the start.i runs from 'E' down to 'A' — each row begins one letter earlier.
2. Inner loop prints down to A. For each i, j runs from i down to 'A', so every row ends with A.
3. Break the line.System.out.println() after the inner loop starts the next (shorter) row.
When i = 'C' you get CBA; when i = 'A' you get A.
Example 2 — Row Count Input
Read the number of rows and compute top = 'A' + rows - 1. Prefer checking hasNextInt() before nextInt() in real apps.
Java
import java.util.Scanner;
public class ReverseDecreasingTriangleInput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int rows = sc.nextInt();
char top = (char) ('A' + rows - 1);
for (char i = top; i >= 'A'; i--) {
for (char j = i; j >= 'A'; j--) {
System.out.print(j);
}
System.out.println();
}
sc.close();
}
}
Output (when user enters 4)
Enter the number of rows: 4
DCBA
CBA
BA
A
How It Works
1. Scale with rows. For 4 rows, top becomes 'D'. Cap rows at 26 so top stays within A–Z.
2. Same nested-loop core. Only the source of top changes — the print logic matches Example 1.
3. Safer input tip. Unchecked nextInt() throws on letters. Prefer:
Safer input
if (!sc.hasNextInt()) {
System.out.println("Enter a whole number from 1 to 26.");
return;
}
int rows = sc.nextInt();
if (rows < 1 || rows > 26) {
System.out.println("Enter a whole number from 1 to 26.");
return;
}
Example 3 — Spaced Letters
Same bounds — print a trailing space after each letter so columns are easier to scan.
Java
public class ReverseDecreasingTriangleSpaced {
public static void main(String[] args) {
char top = 'E';
for (char i = top; i >= 'A'; i--) {
for (char j = i; j >= 'A'; j--) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
Output
E D C B A
D C B A
C B A
B A
A
How It Works
1. Bounds unchanged. Outer still lowers i; inner still walks i..A downward.
2. Only the printed unit changes. Each cell becomes j + " ". Trim trailing spaces later if you need a compact line.
Edge Cases & Pitfalls
Check these before calling the solution done.
j++
Forward instead of reverse
If the inner loop increments toward the end letter, you get Program 6. Keep j-- down to 'A' for reverse rows.
println early
Column of letters
If println is inside the inner loop, each letter lands on its own line. Use print for letters; println only after the inner loop.
Fixed start
Confused with Program 8
Program 8 always starts at the top letter and shortens the stop. This pattern changes the first letter each row.
rows = 1
Single A
Output is just A on one line — a good sanity check.
rows > 26
Beyond Z
Cap or reject — top leaves the alphabet. Keep rows in 1…26 for A–Z demos.
Bad Scanner
Use hasNextInt
Unchecked nextInt() throws on letters — prefer hasNextInt() and clamp to 1…26.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(n²)
O(1)
Spaced letters (Example 3)
O(n²)
O(1)
Total letters printed = n + (n−1) + … + 1 = n(n+1)/2, which is still quadratic in n.
Remember
Key Takeaways
Rule: start moves toward A each row; every row prints descending to A.
Two loops: both decrement — outer for start, inner for i..A.
Break the row: call println only after the inner loop.
Complexity:O(n²) time; O(1) extra space.
One line: for each start i from top down to A, print i..A descending, then println.
Frequently Asked Questions
The outer loop picks the starting letter (E, then D, then C…). The inner loop prints from that start down to A, so the first line is EDCBA and each next line drops the previous leftmost letter.
The outer loop decreases the starting letter each row, and the inner loop decreases letters within that row down to A. That matches the reverse-alphabet output.
Program 6 prints forward suffixes ending at E (ABCDE, BCDE, …). This pattern prints reverse runs ending at A (EDCBA, DCBA, …). Same shrinking widths; opposite letter direction.
Program 8 always starts each row at E and shortens the tail (EDCBA, EDCB, EDC). Program 7 changes the first letter each row (E, then D, then C…).
Because the inner loop runs until j == 'A', so the final character printed on each row is always A.
O(n²) for n rows, because total printed characters are n+(n−1)+…+1 = n(n+1)/2.
Yes. Read rows from Scanner, set top = (char)('A' + rows - 1), then loop i from top down to 'A' and print j from i down to 'A'.
Check sc.hasNextInt() before sc.nextInt(), require n ≥ 1, and cap at 26 so the top letter stays within A–Z.
🤔
Did you know?
This triangle prints reverse letters and shrinks each row: EDCBA, DCBA, CBA, BA, A. Both loops run backward so letters move toward 'A' on every line.