Inverted Forward Repeating Alphabet Triangle in Java

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

What You’ll Learn

Row width shrinks from five to one, but the letter moves forward each row: AAAAA, BBBB, CCC, DD, E. Compare with Program 11 (same shape, letters step down) and worked Java examples, live preview, edge cases, and complexity.

Shape Rule

Wide first, letters forward

Row 1 prints AAAAA, then BBBB, down to a single E.

Outer Loop

Letter advance

for (char i = 'A'; i <= 'E'; i++) picks the letter for each row.

Inner Loop

Width 5…1

for (char j = 'E'; j >= i; j--) shrinks as i rises — print i, not j.

print vs println

Same line / next line

Letters use print; end each row with println().

Live Preview

1–26 rows

Pick a row count and draw the inverted forward triangle in the browser.

O(n²)

Complexity

Total letters = n(n+1)/2; extra memory stays O(1).

Introduction

An inverted forward repeating alphabet triangle starts wide and shrinks by one repeated letter on each new line, while letters advance from A toward the top of the range. With the right angle on the left, the console shows an upside-down staircase of identical letters per row.

In Java you usually solve it with two nested for loops: the outer loop picks the row letter (counting up), the inner loop prints that same letter fewer times each row, then System.out.println() moves to the next line.

Why it matters?

It shows that letter direction and width direction are independent knobs. Flip only the outer loop (A→E vs E→A) and you move between Program 12 and Program 11 without rewriting the shape idea.

Key Highlights

Widest First

Top row repeats A exactly n times.

Letters Advance

Rows go A, B, C, … while widths go n…1.

Print Outer Letter

print(i) in the inner loop; println() after.

Mirror of Program 11

Same widths — opposite letter direction.

In short: for each letter i from A up to top, print i repeatedly (top - i + 1) times, then call System.out.println().

📝 Problem & Approach

Given a positive integer rows (or a fixed top letter like 'E'), print a left-aligned inverted triangle where letters advance from A and widths shrink from rows down to 1.

Java
// First 5 rows (conceptual shape)
// AAAAA
// BBBB
// CCC
// DD
// E

Inputs & Outputs

ItemTypeDescription
rowsintNumber of triangle lines (typically 1–26). Top letter = 'A' + rows - 1.
Printed outputtextLeft-aligned rows; row r (0-based) prints letter 'A' + r exactly rows - r times.

Minimal workflow

Pseudocode
top = 'A' + rows - 1
for row from 0 to rows - 1:
    ch = 'A' + row
    repeat = rows - row
    for k from 1 to repeat:
        print ch (no newline)
    print newline

Approach comparison

ApproachIdeaBest for
Nested char loopsOuter A…top + inner top…i widthLearning and interviews
String.valueOf(ch).repeat(repeat)Build a whole row in one callShorter production-style demos

⚡ Quick Reference

GoalPattern
Walk letters forwardfor (char i = 'A'; i <= 'E'; i++)
Shrink repeat countfor (char j = 'E'; j >= i; j--)
Print row letterSystem.out.print(i); — not j
End the rowSystem.out.println();
One-line row shortcutSystem.out.println(String.valueOf(ch).repeat(repeat));
Letters step downSee Program 11 (EEEEE, DDDD, …)

📋 print vs println vs String.repeat

Same triangle — different ways to emit characters.

System.out.print
same line

Prints a letter without moving to the next line

System.out.println
new line

Ends the current row after all repeats are printed

String.valueOf(ch).repeat(n)
whole row

Builds n copies of ch at once — skip the inner loop

Learning tip
print i

Master printing the outer letter before the string shortcut

Context

When This Pattern Shows Up

Reach for this triangle when practicing inverted widths with forward letters.

  1. After Program 11

    Keep shrinking widths; flip only the letter direction to A→E.

  2. Independent knobs

    Letter direction and width direction can flip separately.

  3. Index-based formula

    Practice ch = 'A' + row and repeat = rows - row.

  4. Gateway to Program 13

    Next: sequential letters that keep advancing across rows.

  5. Not a UI layout tool

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

Key benefit: one small program that proves letter direction is independent of inverted width — a core alphabet-pattern skill.

🔮 Live Preview

Choose a row count between 1 and 26 and draw the inverted forward repeating alphabet triangle in the browser.

Try 5 (AAAAA…E), 4 (AAAA…D), or 7. Max 26 keeps letters in A–Z.

Live result
Press "Draw pattern".

Examples Gallery

Three complete Java programs — fixed top letter, console input, and a String.repeat shortcut. Click View Output to reveal sample console results.

📚 Getting Started

Print five inverted forward rows with classic nested char loops.

Example 1 — Fixed 'A' up to 'E'

Hard-coded range — ideal for first demos and screenshots.

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

How It Works

When i = 'A', the inner loop runs from E down to A (5 times) and prints A. When i = 'B', it prints BBBB, and so on until a single E. Printing i (not j) keeps each row uniform.

📈 Practical Variant

Let the user choose the height at runtime.

Example 2 — User Input Version

Use row index: ch = 'A' + row and repeat = rows - row. Check hasNextInt() in real apps.

Java
import java.util.Scanner;

public class InvertedForwardInput {
    public static void main(String[] args) {
        int rows;
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter the number of rows: ");
        rows = sc.nextInt();

        char top = (char)('A' + rows - 1);

        for (int row = 0; row < rows; row++) {
            char ch = (char)('A' + row);
            int repeat = rows - row;
            for (int k = 1; k <= repeat; k++) {
                System.out.print(ch);
            }
            System.out.println();
        }

        sc.close();
    }
}

How It Works

For rows = 4, row 0 prints A four times, row 1 prints B three times, and so on. Clamp rows to 1–26 so letters stay within A–Z. (top is shown for clarity; the index formula does the real work.)

⚡ Shortcut Style

Same shape without an explicit inner print loop.

Example 3 — String.valueOf(ch).repeat(repeat)

Build each repeated-letter row in one call, then print it.

Java
public class InvertedForwardString {
    public static void main(String[] args) {
        int rows = 5;

        for (int row = 0; row < rows; row++) {
            char ch = (char)('A' + row);
            int repeat = rows - row;
            System.out.println(String.valueOf(ch).repeat(repeat));
        }
    }
}

How It Works

String.valueOf(ch).repeat(repeat) creates a string of length repeat filled with ch. Great once you understand the nested-loop idea; keep the two-loop version for exams that ask you to show both bounds.

🧠 How the Algorithm Prints Rows

1

Set up

Import java.util.Scanner when reading input. Fix the top letter or compute it from rows.

Setup
2

Outer loop (letter)

for (char i = 'A'; i <= 'E'; i++) selects the character printed on the row.

A → E
3

Inner loop (width)

for (char j = 'E'; j >= i; j--) runs 5, 4, 3… times; print i with System.out.print(i).

5..1
4

New line

System.out.println() ends the row so the next outer iteration starts fresh.

Break
=

Triangle complete

Total letters: n+(n-1)+…+1 = n(n+1)/2O(n²) time, O(1) extra memory.

🔎 Worked Walkthrough — 'A' up to 'E'

Trace each outer-loop value of i and count how many times the inner loop runs.

iInner j rangePrinted rowRepeats
'A''E'..'A'AAAAA5
'B''E'..'B'BBBB4
'C''E'..'C'CCC3
'D''E'..'D'DD2
'E''E'..'E'E1

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

Use Cases

Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.

1. Letter vs Width Knobs

Clearest demo that forward letters can pair with shrinking widths.

Example: swap only the outer loop direction to get Program 11.

2. Pair with Program 11

Teach letter direction as a one-line change.

Example: side-by-side EEEEE/DDDD vs AAAAA/BBBB.

3. Index Formulas

Practice 'A' + row and rows - row without char countdown tricks.

Example: row 2 → letter C, repeat = n-2.

4. Case & Fill Variants

Swap to lowercase or mix digits once the loops work.

Example: start from 'a' + row.

5. Complexity Intuition

Descending triangular totals still make O(n²) concrete.

Example: 5+4+…+1 = 15 for n = 5.

6. Input Validation Labs

Pair the pattern with hasNextInt() and 1–26 clamps.

Example: reject rows <= 0 or rows > 26.

Pro Tip: say “letters go up, width goes down” before coding — that story prevents mixing Program 11’s countdown letter with this page.

Advantages

Why this pattern earns a spot right after the inverted countdown triangle.

  1. 1. Instant Visual Feedback

    Wrong letter direction shows up immediately as EEEEE instead of AAAAA.

  2. 2. Minimal Concepts

    Only loops, chars, and console output — no arrays required.

  3. 3. Easy to Mirror

    Flip to Program 11 by counting letters downward instead.

  4. 4. O(1) Extra Memory

    Streaming output needs no storage beyond loop counters.

Pro Tip: learn the nested-loop version first; treat String.valueOf(ch).repeat(repeat) as a polish shortcut afterward.

Usage Tips

Small habits that keep alphabet-pattern code clean.

  1. 1. Name the Roles

    Use ch = 'A' + row and repeat = rows - row — clearer than overloaded char bounds alone.

  2. 2. Prefer hasNextInt()

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

  3. 3. Keep println Outside

    Only call println() after the inner loop finishes the row.

  4. 4. Clamp to 26

    For A–Z demos, reject or clamp rows > 26.

  5. 5. Dry-Run One Small n

    Trace rows = 3 (AAA, BB, C) on paper before coding larger demos.

Pro Tip: if you get EEEEE, DDDD, CCC instead of AAAAA, BBBB, CCC, you reused Program 11’s countdown outer loop.

Common Pitfalls

Mistakes that commonly break inverted forward repeating alphabet patterns.

  1. 1. Printing j Instead of i

    Rows become countdown sequences instead of repeated letters.

    → Always System.out.print(i) (or ch) for this shape.

  2. 2. Using Program 11’s Outer Loop

    Counting i from top down to A prints EEEEE first instead of AAAAA.

    → Keep i (or row) advancing from A upward.

  3. 3. println Inside the Inner Loop

    Each letter lands on its own line — you get a column, not a triangle.

    → Use print for letters; println only after the inner loop.

  4. 4. Blind nextInt()

    Letters or empty input throw InputMismatchException.

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

  5. 5. rows > 26 Without a Policy

    'A' + rows - 1 can leave the A–Z range.

    → Clamp to 26 or define wrap/error behavior explicitly.

Edge Cases

Check these inputs before calling the solution done.

rows = 1

Single letter

Output is just A on one line.

rows = 0

Empty pattern

Treat as invalid; re-prompt instead of silent empty output.

Negative

rows < 0

Invalid height — validate before looping.

rows > 26

Past Z

Clamp or error — char math leaves A–Z.

Bad input

Non-numeric input

nextInt() throws — check hasNextInt().

Case

Lowercase variant

Same loops work with 'a' + row.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Flip to Program 11

  • Keep shrink; letters step E→A
  • Continue with Program 11

2. Growing forward (Program 9)

  • Widths grow 1…n with A, BB, CCC
  • See Program 9

3. Safe input loop

  • Use hasNextInt() until 1 <= rows <= 26
  • Then draw the triangle

4. Lowercase version

  • Use 'a' + row as the row letter
  • Shows the loop structure is reusable

Notes

  • Triangular count. Total letters for n rows is still n(n+1)/2 — hence O(n²) time.
  • Print the outer letter; the inner loop only decides how many times (shrinking).
  • Validate 1 <= rows <= 26 for interactive A–Z programs.
  • This page is left-aligned. Centered pyramids need leading spaces — covered later in the series.

Quick Takeaway: outer loop advances the letter (A→top), inner loop shrinks the width, then break the line — that is the whole pattern.

⏱️ Time and Space Complexity

ProgramTimeExtra space
Nested loops (Examples 1–2)O(rows²)O(1)
String.valueOf(ch).repeat(repeat) (Example 3)O(rows²)O(rows) per row string (temporary)
Wrap Up

🎉 Conclusion

The inverted forward repeating alphabet triangle is a small nested-loop exercise with lasting payoff: forward letters vs shrinking width, and O(n²) intuition. Master the classic two-loop version, then optionally shorten rows with String.valueOf(ch).repeat(repeat).

Practice the three examples above, then compare with Program 11 or continue to Program 13’s sequential letters.

Print the outer letter with print, end rows with println, and use repeat = rows - row (not Program 11’s countdown letter) for this shape.

💡 Best Practices

✅ Do

  • Explain outer = forward letter, inner = shrinking width before coding
  • Use System.out.print for letters and println after each row
  • Validate 1 <= rows <= 26 for interactive programs
  • Check hasNextInt() before calling nextInt()
  • State O(n²) time when asked about complexity

❌ Don’t

  • Print the inner-loop variable for this repeating shape
  • Reuse Program 11’s countdown outer letter here
  • Call println inside the inner letter loop
  • Ignore bad console input in user-facing demos
  • Allow rows > 26 without a clear policy

Key Takeaways

Knowledge Unlocked

Five things to remember about this alphabet pattern

Print the inverted forward repeating triangle the beginner-friendly way.

5
Core concepts
02

Outer loop

Advances A→top

Code
A 03

Inner loop

Shrinks with print(i)

Code
04

println

Ends each row

I/O
O 05

Complexity

O(n²) time

Analysis

❓ Frequently Asked Questions

Program 11 prints EEEEE, DDDD, ... (letters step down). Program 12 prints AAAAA, BBBB, ... (letters step up) with the same inverted widths 5..1.
When i is A, the inner loop runs from E down to A (5 times) and prints A each time. Next i becomes B, the inner loop runs 4 times (E..B) and prints B.
j only controls how many times the loop runs. Printing i keeps the entire row the same letter; printing j would step letters across the row.
Because the inner loop runs from the fixed top letter down to the current i. As i increases, the loop has fewer iterations.
System.out.print stays on the same line. System.out.println ends the current line. Letters use print; the row break uses println after the inner loop.
O(n²) where n is the number of rows. Total System.out.print calls equal n+(n-1)+…+1 = n(n+1)/2.
Yes. System.out.println(String.valueOf(ch).repeat(repeat)) prints a full repeated-letter row in one call (Java 11+). Nested loops are better for learning; String.repeat is a handy shortcut later.
Check sc.hasNextInt() before sc.nextInt() and clamp rows between 1 and 26 so bad input does not throw InputMismatchException or walk past Z.

Did you Know? 🔊

This is the forward-letter twin of Program 11: same inverted widths (5…1), but letters advance A→E instead of stepping down. Print the outer loop letter inside the inner loop so each row stays uniform.

Continue to Alphabet Pattern 13

Next up: sequential letters that keep advancing across the whole triangle.

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