Reverse Right-Angled Triangle Alphabet Pattern in Java

Beginner
⏱️ 8 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Nested Loops

What You’ll Learn

Print a reverse alphabet right-angled triangle: each row has one more character than the previous, and letters go from a top letter down toward AE, ED, EDC, EDCB, EDCBA. Same geometry as Program 1, but descending along the alphabet. Includes a live preview, worked Java examples, edge cases, and complexity.

Shape Rule

Growing reverse rows

Row k prints k letters from top down to a row end letter.

Outer Loop

Row end letter

for (char i = top; i >= 'A'; i--) picks the last letter.

Inner Loop

Always from top

j starts at top and prints down to i.

Char Arithmetic

j--

Decrementing a char walks the alphabet backward.

Live Preview

1–10 rows

Pick a height and draw the reverse triangle instantly.

O(n²)

Complexity

Triangular letter count: n(n+1)/2 writes.

Introduction

A reverse alphabet right-angled triangle grows like Program 1, but every row starts at a fixed top letter and counts downward until a row-specific end letter.

In Java you solve it with nested char loops: the outer loop walks the end letter from top down to A, and the inner loop always restarts at top and prints down to that end.

Why it matters?

It locks in reverse character iteration — the same j-- skill used in many reverse triangles, diagonals, and mirrored alphabet labs.

Key Highlights

Growing Rows

1, 2, 3, … letters per row.

Always From Top

Inner loop restarts at the top letter.

Descending Letters

Print with j-- down to the end.

Mirror of Program 1

Same triangle; opposite letter direction.

In short: for each end letter i from top down to A, print top..i, then call println().

📝 Problem & Approach

Given a row count n (or fixed A–E), print a left-aligned triangle of descending alphabet prefixes.

Java
// Five rows (top = E)
// E
// ED
// EDC
// EDCB
// EDCBA

Inputs & Outputs

ItemTypeDescription
rows / topint / charNumber of rows, or top letter where top = 'A' + rows - 1.
Printed outputtextGrowing reverse prefixes from top down to A on the last row.

Minimal workflow

Pseudocode
top = 'A' + rows - 1
for i from top down to 'A':
    for j from top down to i:
        print j
    print newline

Approach comparison

ApproachIdeaBest for
Char loops downOuter/inner both decrementMatching this classic sample
Index + char arrayWalk indices into A..ZWhen you already think in 0-based rows

⚡ Quick Reference

GoalPattern
Top letterchar top = (char)('A' + rows - 1);
Outer (end letter)for (char i = top; i >= 'A'; i--)
Inner (print)for (char j = top; j >= i; j--) System.out.print(j);
End the rowSystem.out.println();
Forward triangleSee Program 1
LowercaseUse 'a' as the base instead of 'A'

📋 print vs println vs Direction

Same triangle idea as Program 1 — only letter direction changes.

System.out.print(j)
letter

Prints each descending letter on the current row

System.out.println
break

Ends the row after top..i finishes

Program 2
E..i

Inner loop counts down from top

Program 1
A..i

Inner loop counts up from A

Context

When This Pattern Shows Up

Reach for this when teaching reverse character loops on a growing triangle.

  1. Right after Program 1

    Keep the triangle; flip letter direction to descending.

  2. Char decrement drills

    Practice j-- and j >= i bounds safely.

  3. Before Program 3

    Next you change only the starting letter while counting forward.

  4. Top-letter math

    Practice top = 'A' + rows - 1 for any height.

  5. Not a UI layout tool

    This is a console teaching pattern — not how you build modern app screens.

Key benefit: one bound change (j >= i with j--) turns a forward triangle into a reverse one.

🔮 Live Preview

Choose between 1 and 10 rows and draw the reverse alphabet triangle in the browser.

Try 5 (classic E…EDCBA) or 4 (D…DCBA). Max 10 keeps the preview readable.

Live result
Press "Draw pattern".

Examples Gallery

Three complete Java programs — fixed A–E, user-chosen row count, and a spaced-letter variant. Click View Output to reveal sample console results.

📚 Getting Started

Print five reverse rows with nested char loops.

Example 1 — Fixed Top E

Outer loop sets the last letter for each row (E, D, C, B, A). Inner loop prints from 'E' down to that letter.

Java
public class ReverseTriangle {
    public static void main(String[] args) {
        for (char i = 'E'; i >= 'A'; i--) {
            for (char j = 'E'; j >= i; j--) {
                System.out.print(j);
            }
            System.out.println();
        }
    }
}

How It Works

When i = 'C', the inner loop prints E, D, CEDC. When i = 'A', it prints the full reverse run EDCBA.

📈 Practical Variant

Let the user choose how many rows to print.

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 ReverseTriangleInput {
    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 = top; j >= i; j--) {
                System.out.print(j);
            }
            System.out.println();
        }

        sc.close();
    }
}

How It Works

For 4 rows, top becomes 'D'. Cap rows at 26 so top stays within A–Z.

⚡ Readability Variant

Same reverse triangle with spaces between letters.

Example 3 — Spaced Letters

Print a trailing space after each letter so columns are easier to scan.

Java
public class ReverseTriangleSpaced {
    public static void main(String[] args) {
        char top = 'E';

        for (char i = top; i >= 'A'; i--) {
            for (char j = top; j >= i; j--) {
                System.out.print(j + " ");
            }
            System.out.println();
        }
    }
}

How It Works

Loop bounds are unchanged — only the printed unit becomes j + " ". Trim trailing spaces later if you need a compact line.

🧠 How the Algorithm Prints Rows

1

Outer loop (rows)

The outer loop runs i from top down to 'A'. Each value is the last letter on that row.

Row control
2

Inner loop (descending)

Start at top and print down to i with System.out.print(j).

Print letters
3

New line

System.out.println() ends the current row and moves to the next line.

Next row
4

Repeat until A

Rows grow by one letter each time until the full reverse run prints.

Grow
=

Reverse letter triangle

You print 1+2+…+n letters — O(n²) time, O(1) extra memory.

🔎 Worked Walkthrough — top E

Trace each outer value of i and the letters printed on that row.

i (end)Inner j rangePrinted row
EE..EE
DE..DED
CE..CEDC
BE..BEDCB
AE..AEDCBA

Total letters: 1 + 2 + 3 + 4 + 5 = 15 = 5×6/2.

Use Cases

Where this reverse triangle (and its descending loops) shows up beyond the homework prompt.

1. Direction Practice

Clearest alphabet demo of counting letters downward.

Example: flip bounds to Program 1 and compare.

2. Pair with Program 1

Same triangle geometry — forward vs reverse fill.

Example: print both side by side for n = 5.

3. Top-Letter Labs

Practice computing top from a row count.

Example: rows 1..10 map to A..J.

4. Spaced Output

Add separators without changing loop structure (Example 3).

Example: print j + " " for readable columns.

5. Complexity Intuition

Triangular sums make O(n²) easy to see.

Example: 5 rows print 15 letters total.

6. Alphabet Caps

Practice limiting input so top stays in A–Z.

Example: reject rows > 26 or clamp it.

Pro Tip: say “always start at top, stop at the row end letter” before coding — that story prevents wrong inner bounds.

Advantages

Why this pattern earns a spot right after the forward alphabet triangle.

  1. 1. Instant Visual Feedback

    Wrong direction or bounds show up immediately as a non-reverse triangle.

  2. 2. Tiny Change from Program 1

    Same structure; only loop direction and comparison flip.

  3. 3. Natural Char Decrement

    Java char arithmetic makes reverse walks feel natural.

  4. 4. O(1) Extra Memory

    Streaming output needs no storage beyond loop variables.

Pro Tip: master Program 1 first; treat this page as the same story with arrows reversed.

Usage Tips

Small habits that keep reverse-triangle code clean.

  1. 1. Restart Inner at Top

    Every row starts from the same top letter; only the end changes.

  2. 2. Use j >= i with j--

    That pair is what produces E, ED, EDC, …

  3. 3. Prefer hasNextInt()

    Avoid crashes when the user types letters instead of a number.

  4. 4. Cap at 26 Rows

    Beyond Z you need a wrap/stop policy for top.

  5. 5. Dry-Run Row C

    Trace E D C on paper before coding larger n.

Pro Tip: if every row starts with a different letter and runs forward to E, you wrote Program 3 — not this pattern.

Common Pitfalls

Mistakes that commonly break reverse alphabet triangles.

  1. 1. Using Forward Inner Bounds

    Writing j = 'A'; j <= i; j++ prints Program 1 instead.

    → Use j = top; j >= i; j--.

  2. 2. Wrong Comparison

    j > i skips the end letter on every row.

    → Keep j >= i so the row end letter is included.

  3. 3. Overflowing Z

    Large rows makes top walk past Z.

    → Cap input at 26 or define a wrap policy.

  4. 4. Blind nextInt()

    Letters or empty input throw InputMismatchException.

    → Check hasNextInt() and re-prompt on failure.

  5. 5. Skipping println

    All letters print on one continuous line.

    → Call println after each inner loop finishes.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single letter

Output is just A.

rows = 5

Classic sample

Through EDCBA.

rows = 4

Shorter triangle

Top is D → DDCBA.

rows > 26

Past Z

Reject, clamp, or wrap — decide explicitly.

Bad input

Non-numeric input

nextInt() throws — check hasNextInt().

Case

Lowercase

Same loops with 'a' as the base.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Flip to forward

2. Add spaces

  • Print j + " " (Example 3)
  • Keep the same loop bounds

3. Change only the start

4. Star triangle twin

Notes

  • Same top every row. Only the end letter moves downward as rows grow.
  • Total letters for n rows is the triangular number n(n+1)/2.
  • Compute top = (char)('A' + rows - 1) to generalize any height.
  • This is the descending mirror of Program 1’s forward triangle.

Quick Takeaway: start every row at the top letter, print down to the row end, then break the line — that is the whole triangle.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Fixed / input (Examples 1–2)O(n²)O(1)
Spaced letters (Example 3)O(n²)O(1)

Row k prints k letters; summing 1..n gives n(n+1)/2 character writes.

Wrap Up

🎉 Conclusion

The reverse alphabet right-angled triangle is a small nested-loop exercise with lasting payoff: fixed top letter, descending inner walk, and growing row length. Master the classic E…EDCBA sample, then try user input and optional spacing.

Practice the three examples above, then continue to Program 3’s triangle where each row starts one letter earlier but still runs forward.

Compute a top letter, print top..i on each row, and break only after the inner loop finishes.

💡 Best Practices

✅ Do

  • Restart the inner loop at top every row
  • Use j >= i with j-- for descending output
  • Compute top = (char)('A' + rows - 1)
  • Check hasNextInt() and cap at 26
  • State O(n²) when asked about complexity

❌ Don’t

  • Use forward A..i bounds for this pattern
  • Skip println after each row
  • Let rows exceed 26 without a policy
  • Confuse this with Program 3’s changing start letter
  • Assume empty input is safe for nextInt()

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the reverse alphabet right-angled triangle the beginner-friendly way.

5
Core concepts
T 02

Top

Inner always starts here

Code
-- 03

Direction

j-- down to i

Code
04

println

Ends each row

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

The outer loop sets the last letter on each row from E down to A. For each outer letter i, the inner loop starts at E and prints down to i, so rows grow longer while letters remain in reverse order.
Because the inner loop always starts at top (E in the fixed example). Only the end letter changes with the outer-loop bound, so the triangle grows by one character each row.
Yes. Read rows from the console and set top = (char)('A' + rows - 1). Then loop i from top down to 'A' and print j from top down to i.
Use Program 1: loop upward from 'A' and print to the current end letter. This page is the descending mirror of that pattern.
System.out.print stays on the same line for each letter. System.out.println ends the row after the inner loop finishes.
O(n²) for n rows, because the total printed letters are 1+2+...+n = n(n+1)/2.
Check sc.hasNextInt() before sc.nextInt(), require n ≥ 1, and cap at 26 so the top letter stays within A–Z.
Yes. Use 'a' as the base: top = (char)('a' + rows - 1), then loop the same way downward.

Did you Know? 🔊

This reverse right-angled alphabet triangle prints letters from a top letter down to A on each row. For 5 rows, the output is E, ED, EDC, EDCB, and EDCBA. In Java, decrementing a char works naturally: (char)('E' - 1) becomes 'D'.

Continue to Alphabet Pattern 3

Next up: each row starts one letter earlier, but letters still run forward to the top.

Program 3 tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful