Inverted Repeating-Letter Triangle in Java

Beginner
⏱️ 5 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

What You’ll Learn

First row: five Es. Each following row is one character shorter and uses the next letter down: EEEEE, DDDD, CCC, BB, A.

Compare with program 9 (width grows, forward letters) and program 10 (width grows with letters E→A). Here j runs from 65 up to i while i steps down from 69 to 65.

⭐ Pattern Output

For 5 rows (i from 69 down to 65):

Output
EEEEE
DDDD
CCC
BB
A
1

Complete Java Program

Outer i from 69 down to 65. Inner j from 65 up to i; each iteration prints (char) i.

Java
public class Main {
    public static void main(String[] args) {
        int i, j;
        for (i = 69; i >= 65; i--) {
            for (j = 65; j <= i; j++) {
                System.out.print((char) i);
            }
            System.out.println();
        }
    }
}

🧠 How It Works

1

Class and main

Main holds public static void main(String[] args), the program entry point.

Setup
2

Outer loop: row letter

for (i = 69; i >= 65; i--) walks E, D, C, B, A. That ASCII value is both the symbol and the upper bound for j.

Descending letter
3

Inner loop: repeat count

for (j = 65; j <= i; j++) runs i - 65 + 1 times. Each time, System.out.print((char) i) prints the same letter.

Shrinking width
4

New line

System.out.println() ends the row; i-- picks the next (shorter) row.

Next row
=

Shrinking repeat rows

Row lengths are n, n−1, …, 1, so total output is n(n+1)/2 characters — O(n²) for n starting width.

2

Variation — User Input Version

Let base = 65 and top = base + rows - 1. Outer i from top down to base; inner j from base to i. Clamp rows to 1–26:

Java
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));
        final int base = 65;
        int top = base + rows - 1;
        int i, j;

        for (i = top; i >= base; i--) {
            for (j = base; j <= i; j++) {
                System.out.print((char) i);
            }
            System.out.println();
        }

        sc.close();
    }
}

💡 Tips for Enhancement

Try These

  • Growing repeat triangle: program 9
  • Growing width, letters E→A: program 10
  • char style: char ch = (char) ('A' + rows - 1), outer k from rows to 1, inner loop k prints of ch, then ch--
  • Lowercase: set base = 97

Avoid

  • System.out.print((char) j) unless you want A, B, C… across the row
  • Mixing program-10 inner bounds (j from top down) with this outer i — the geometry won’t match

Key Takeaways

1

Outer i sets the letter; inner j from base to i sets how many copies.

2

Row length = i - base + 1 — shrinks as i steps down.

3

O(n²) characters for n rows.

4

Complement to programs 9 and 10: inverted width with repeated letters.

❓ Frequently Asked Questions

i starts at 69 ('E'), and j runs from 65 through 69—five values—each printing (char) i.
That would print a staircase of letters along the row. Here every column on a row must show the same letter i.
Program 10 uses inner j from top down to i (narrow-to-wide rows). Program 11 uses j from base up to i (wide-to-narrow rows).
O(n²) for n rows: n(n+1)/2 characters.

More Java alphabet patterns

Programs 10 and 11 both walk i from E down to A; the inner loop bounds choose growing vs shrinking row width.

All Alphabet Patterns →
Did you know?

A char-based version keeps char ch, loops k from rows down to 1, prints ch k times, then ch--. Same picture; this page’s sample folds letter and width into one ASCII outer index i.

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