Reverse Repeating-Letter Triangle in Java

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

What You’ll Learn

Same repeating idea as program 9, but letters run E → D → C → B → A while row widths still grow 1, 2, 3, 4, 5.

The outer loop uses i from 69 ('E') down to 65 ('A'); the inner loop only decides how many times to print (char) i.

⭐ Pattern Output

When you run the program with five rows (i from 69 to 65):

Output
E
DD
CCC
BBBB
AAAAA
1

Complete Java Program

Outer i from 69 to 65. Inner j from 69 down 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 = 69; 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--) picks E, then D, C, B, A. That value is what you print on the row.

Descending letter
3

Inner loop: repeat count

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

Repeat
4

New line

System.out.println() ends the row; i-- moves to the next letter.

Next row
=

E-first, same widths

The outer loop still produces row widths 1, 2, …, n; only the printed letter runs E→A. Total characters 1+2+…+nO(n²).

2

Variation — User Input Version

Let top = 65 + rows - 1 and base = 65. Outer i from top down to base; inner j from top down 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 = top; j >= i; j--) {
                System.out.print((char) i);
            }
            System.out.println();
        }

        sc.close();
    }
}

💡 Tips for Enhancement

Try These

  • Forward repeat triangle: program 9
  • Same shape with char ch: row index k from 1 to n, ch = (char) (top - k + 1), inner loop k times
  • Lowercase: use base = 97 and top = 97 + rows - 1
  • Cap rows so letters stay in the range you want

Avoid

  • System.out.print((char) j) unless you want descending letters along the row
  • Incrementing i on the outer loop when you need E → A row order
  • Rows so large that i drops below your intended alphabet floor

Key Takeaways

1

Outer i is both the row’s letter and the lower bound for j.

2

Inner loop iterations = top - i + 1 with fixed top = 69 in the five-row demo.

3

O(n²) characters for n rows.

4

Mirrors program 9: ascending vs descending outer letter with the same triangle widths.

❓ Frequently Asked Questions

j is only a counter. The repeated symbol on the row is i.
In the fixed version, 69 is 'E' and acts as top. For variable rows, use top = 65 + rows - 1 and start j at top each time.
Program 9 walks letters upward from A; program 10 walks i downward from E. The inner bounds are built the same way relative to top and i.
O(n²) for n rows: n(n+1)/2 characters.

More Java alphabet patterns

Program 9 and 10 share the same nested-loop skeleton—only the outer i direction changes.

All Alphabet Patterns →
Did you know?

An equivalent char version: for row k from 1 to n, set ch = (char) ('A' + n - k) and print ch exactly k times—no inner index j tied to ASCII.

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