Inverted Repeating-Letter Triangle in Java

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):
EEEEE
DDDD
CCC
BB
AComplete Java Program
Outer i from 69 down to 65. Inner j from 65 up to i; each iteration prints (char) i.
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
Class and main
Main holds public static void main(String[] args), the program entry point.
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.
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.
New line
System.out.println() ends the row; i-- picks the next (shorter) 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.
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:
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
charstyle:char ch = (char) ('A' + rows - 1), outerkfromrowsto1, inner loopkprints ofch, thench--- Lowercase: set
base = 97
Avoid
System.out.print((char) j)unless you want A, B, C… across the row- Mixing program-10 inner bounds (
jfromtopdown) with this outeri— the geometry won’t match
Key Takeaways
Outer i sets the letter; inner j from base to i sets how many copies.
Row length = i - base + 1 — shrinks as i steps down.
O(n²) characters for n rows.
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.i.j from top down to i (narrow-to-wide rows). Program 11 uses j from base up to i (wide-to-narrow rows).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.
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.
12 people found this page helpful
