Java Reverse Alphabet Triangle Pattern (Fixed Start)

Beginner
7 min read
Updated: Sep 2026
3 programs
Live preview

What Is This Pattern?

A reverse fixed-start alphabet triangle always begins each row at the same top letter and counts down, while the stopping letter rises so the reverse tail gets shorter.

Remember
Rule: for stop letter i from A to last,
      print last down through i

EDCBA
EDCB
EDC
ED
E         ← 5 rows (left edge fixed at E)

Same widths as Program 7 (5, 4, 3, 2, 1), but Program 7 moves the left edge (EDCBA, DCBA, …). Here the left edge stays put. Compare also with Program 5, which shrinks forward prefixes from A.

How to Solve It

Two ways to emit the same shape — start with nested char loops, then optionally reverse a prefix once and take shorter leading slices.

MethodIdeaBest for
Nested char loopsOuter = rising stop; inner = top..stop downwardLearning, interviews, exams
Reverse + substring(0, len)Build EDCBA… once, take shorter prefixesShorter demos once loops click

Pseudocode

Pseudocode
top = lastLetter
for stop from 'A' to top:
    for ch from top down to stop:
        print ch (no newline)
    print newline

Cheat sheet

GoalPattern
Raise stop letterfor (char i = 'A'; i <= top; i++)
Print top..i reversefor (char j = top; j >= i; j--) System.out.print(j);
End the rowSystem.out.println();
Top letter from rowschar top = (char)('A' + rows - 1);
One-line row shortcutReverse the A…top prefix, then substring(0, len) while len shrinks
Moving left edgeProgram 7 — start at i, print down to A

Printing Letters vs Starting a New Line

APIEffectUse for
System.out.printStays on the same lineEach letter
System.out.printlnEnds the current lineAfter the inner loop finishes a row

Print letters without a newline, then end the row once.

Live Preview

Change the row count and the reverse fixed-start triangle updates instantly — every row still begins on the same top letter.

Whole numbers from 1 to 10. Tap a chip or type a value — the preview redraws as you go.

Live result 5 rows · top E · 15 letters
EDCBA
EDCB
EDC
ED
E

Worked Walkthrough — Top = E (5 rows)

Trace each stop letter i as it rises from 'A' to 'E' with top fixed at 'E'.

Stop iInner jPrinted rowLetters
'A'E..AEDCBA5
'B'E..BEDCB4
'C'E..CEDC3
'D'E..DED2
'E'E..EE1

Total letter prints: 5 + 4 + 3 + 2 + 1 = 15 = 5×6/2. The left edge is always E; that triangular sum is why time is O(n²).

Java Programs

Three complete programs: fixed top letter, Scanner input, and a reverse-substring shortcut. Use View Output to reveal sample results.

Example 1 — Fixed Top E

Hard-coded height — every row starts at E; the stop letter rises to shorten the tail.

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

How It Works

1. Outer loop raises the stop. i runs from 'A' to 'E' — that is how far down the reverse run goes.

2. Inner loop always starts at E. For each i, j runs from 'E' down to i, so every row begins with E.

3. Break the line. System.out.println() after the inner loop starts the next (shorter) row.

When i = 'C' you get EDC; when i = 'E' you get E.

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 FixedStartReverseTriangleInput {
    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 = 'A'; i <= top; i++) {
            for (char j = top; j >= i; j--) {
                System.out.print(j);
            }
            System.out.println();
        }

        sc.close();
    }
}

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 — Reverse + substring(0, len)

Build the first reverse row once, then take shorter leading prefixes — same shape, no nested letter loop.

Java
public class FixedStartReverseSubstring {
    public static void main(String[] args) {
        int rows = 5;
        String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        String top = new StringBuilder(letters.substring(0, rows))
                .reverse()
                .toString();

        for (int len = rows; len >= 1; len--) {
            System.out.println(top.substring(0, len));
        }
    }
}

How It Works

1. Take and reverse the prefix. ABCDE reversed becomes EDCBA — the first printed row.

2. Shrink the leading slice. substring(0, 5) is the full row; substring(0, 4) drops the trailing A; and so on down to E.

3. Learn loops first. Use Examples 1–2 when you need to show nested bounds; treat this as a polish shortcut afterward.

Edge Cases & Pitfalls

Check these before calling the solution done.

j = i

Program 7 by mistake

If the inner loop starts at i instead of top, you print EDCBA, DCBA, … Use for (char j = top; j >= i; j--).

j >= 'A'

No shrinking

Stopping at 'A' every time reprints the full reverse run. The stop must be the rising outer variable i.

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.

rows > 26

Past Z

'A' + rows - 1 leaves A–Z when rows > 26. Clamp or reject in interactive programs.

rows = 1

Single A

Output is just A — top and stop coincide. A good sanity check.

Bad Scanner

Use hasNextInt

Unchecked nextInt() throws on letters — prefer hasNextInt() and clamp to 1…26.

Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(n²)O(1)
Reverse + substring (Example 3)O(n²)O(n) for the reversed prefix and temporary row strings

Total letters printed = n + (n−1) + … + 1 = n(n+1)/2, which is still quadratic in n.

Key Takeaways

  • Rule: always start at the top letter; raise the stop i so each reverse row shortens.
  • vs Program 7: same widths — here the left edge stays fixed; there the left edge moves.
  • Break the row: call println only after the inner loop.
  • Complexity: O(n²) time; O(1) extra space for nested loops.

One line: for stop i from 'A' to the top letter, print top down through i, then println.

Frequently Asked Questions

Because the inner loop always starts at the top letter (E in the 5-row example) and counts down. So the first printed character each row is always E.
The outer loop increases the stopping point for the inner loop. That shortens the tail each row, producing EDCBA, then EDCB, then EDC, and so on.
Program 7 changes the first letter each row (E, then D, then C…). Program 8 keeps the first letter fixed and only shortens the tail.
Program 5 prints forward prefixes from A (ABCDE, ABCD, …). This pattern prints reverse prefixes from a fixed top (EDCBA, EDCB, …). Same shrinking idea; opposite letter direction and left edge.
Every row would print the full reverse run (EDCBA each time) with no shrinking.
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 'A' to top and print j from top down to i.
Check sc.hasNextInt() before sc.nextInt(), require n ≥ 1, and cap at 26 so the top letter stays within A–Z.

Did you know?

Every row begins with 'E' (in the 5-row example) because the inner loop always starts from that top letter. The outer loop only increases the stopping point, so the tail gets shorter: EDCBA, EDCB, EDC, ED, E.

Next: Repeating Alphabet Triangle

Print the same letter repeatedly on each row — A, BB, CCC, DDDD…

Program 9 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