Reverse Repeating-Letter Triangle in Java

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):
E
DD
CCC
BBBB
AAAAAComplete Java Program
Outer i from 69 to 65. Inner j from 69 down 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 = 69; 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--) picks E, then D, C, B, A. That value is what you print on the row.
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.
New line
System.out.println() ends the row; i-- moves to the next letter.
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+…+n — O(n²).
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:
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 indexkfrom 1 to n,ch = (char) (top - k + 1), inner loopktimes - Lowercase: use
base = 97andtop = 97 + rows - 1 - Cap
rowsso letters stay in the range you want
Avoid
System.out.print((char) j)unless you want descending letters along the row- Incrementing
ion the outer loop when you need E → A row order - Rows so large that
idrops below your intended alphabet floor
Key Takeaways
Outer i is both the row’s letter and the lower bound for j.
Inner loop iterations = top - i + 1 with fixed top = 69 in the five-row demo.
O(n²) characters for n rows.
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.69 is 'E' and acts as top. For variable rows, use top = 65 + rows - 1 and start j at top each time.i downward from E. The inner bounds are built the same way relative to top and i.More Java alphabet patterns
Program 9 and 10 share the same nested-loop skeleton—only the outer i direction changes.
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.
12 people found this page helpful
