A reverse repeating alphabet triangle grows by one repeated letter on each new line while letters count downward from the top of the alphabet range.
Remember
Rule: for letter i from top down to 'A',
print i with growing width 1, 2, 3, …
E
DD
CCC
BBBB
AAAAA ← 5 rows (top = 'E')
It is the reverse of Program 9: same growing widths, but letters step E → A instead of A → E. Print the outer letter inside the inner loop so each row stays uniform. Flip the widths in Program 11 to get the inverted twin.
Approach
How to Solve It
Two ways to emit the same shape — start with nested char loops, then optionally shorten with String.repeat.
Method
Idea
Best for
Nested char loops
Outer = letter; inner = growing width; print outer letter
Learning, interviews, exams
String.valueOf(ch).repeat(n)
Build a whole repeated-letter row in one call
Shorter demos once loops click (Java 11+)
Pseudocode
Pseudocode
for i from top down to 'A':
for j from top down to i:
print i (no newline)
print newline
Print letters without a newline, then end the row once.
Try it
Live Preview
Change the height and the reverse repeating triangle updates instantly — including the letter total.
Whole numbers from 1 to 26 (A–Z). Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · 15 letters
E
DD
CCC
BBBB
AAAAA
Trace
Worked Walkthrough — 'E' down to 'A'
Trace each outer-loop value of i and count how many times the inner loop runs.
i
Inner j range
Printed row
Repeats
'E'
'E'..'E'
E
1
'D'
'E'..'D'
DD
2
'C'
'E'..'C'
CCC
3
'B'
'E'..'B'
BBBB
4
'A'
'E'..'A'
AAAAA
5
Total letter prints: 1 + 2 + 3 + 4 + 5 = 15 = 5×6/2. That triangular sum is why time is O(n²).
Code
Java Programs
Three complete programs: fixed letters, Scanner input, and a String.repeat shortcut. Use View Output to reveal sample results.
Example 1 — Fixed 'E' down to 'A'
Hard-coded range — outer letter counts down; inner loop grows and prints that letter.
Java
public class ReverseRepeat {
public static void main(String[] args) {
for (char i = 'E'; i >= 'A'; i--) {
for (char j = 'E'; j >= i; j--) {
System.out.print(i);
}
System.out.println();
}
}
}
Output
E
DD
CCC
BBBB
AAAAA
How It Works
1. Outer loop picks the letter.i runs from 'E' down to 'A'.
2. Inner loop sets the width.j runs from 'E' down to i — once for E, twice for D, and so on.
3. Print the outer letter.System.out.print(i) keeps the whole row the same character.
4. Break the line.System.out.println() after the inner loop starts the next row.
Example 2 — User Input Version
Compute top = 'A' + rows - 1, then grow repeat from 1 as letters count down. Prefer hasNextInt in real apps.
Java
import java.util.Scanner;
public class ReverseRepeatInput {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of rows: ");
int rows = sc.nextInt();
char top = (char) ('A' + rows - 1);
int repeat = 1;
for (char ch = top; ch >= 'A'; ch--) {
for (int k = 1; k <= repeat; k++) {
System.out.print(ch);
}
System.out.println();
repeat++;
}
sc.close();
}
}
Output (when user enters 4)
Enter the number of rows: 4
D
CC
BBB
AAAA
How It Works
1. Prompt and read. Ask for a row count, then read it with sc.nextInt().
2. Compute the top letter. For rows = 4, top is 'D' — first row is D.
3. Grow the repeat count. Start at repeat = 1 and increment after each row so widths become 1, 2, 3, 4.
4. Safer input tip. Bare nextInt() throws on letters. Prefer:
Safer input
if (!sc.hasNextInt()) {
System.out.println("Enter a whole number from 1 to 26.");
return;
}
int rows = sc.nextInt();
if (rows < 1 || rows > 26) {
System.out.println("Enter a whole number from 1 to 26.");
return;
}
Example 3 — String.valueOf(ch).repeat(n)
Build each repeated-letter row in one call — same shape, no explicit character loop (Java 11+).
Java
public class ReverseRepeatString {
public static void main(String[] args) {
int rows = 5;
char top = (char) ('A' + rows - 1);
int repeat = 1;
for (char ch = top; ch >= 'A'; ch--) {
System.out.println(String.valueOf(ch).repeat(repeat));
repeat++;
}
}
}
Output
E
DD
CCC
BBBB
AAAAA
How It Works
1. Same countdown. Still walk ch from top down to 'A'.
2. Build the row.String.valueOf(ch).repeat(repeat) creates a string of length repeat filled with ch.
3. Learn loops first. Use Examples 1–2 when you need to show nested bounds; treat this as a polish shortcut afterward.
Edge Cases & Pitfalls
Check these before calling the solution done.
print(j)
Stepping letters on a row
If you print j instead of i, letters change across the row. Print the outer letter to keep each row uniform.
i++
Forward triangle by mistake
Counting letters upward reprints Program 9. Keep i-- from the top letter down to 'A'.
println inside
Column of letters
If println is inside the inner loop, each letter lands on its own line. Use print for letters; println only after the inner loop.
rows > 26
Past Z
'A' + rows - 1 leaves A–Z when rows > 26. Clamp or reject in interactive programs.
rows = 1
Single A
Output is just A — top and tip coincide. A good sanity check.
Bad input
Use hasNextInt
nextInt() throws on letters — check hasNextInt() and require 1–26.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(rows²)
O(1)
String.repeat (Example 3)
O(rows²)
O(rows) per temporary row string
Total letters = 1 + 2 + … + n = n(n + 1)/2 — still quadratic in n. Same totals as Program 11; only the print order of widths differs.
Remember
Key Takeaways
Rule: countdown letter i; print i with growing width 1, 2, 3, …
Reverse of Program 9: same growing widths — letters step down instead of up.
Break the row: call println only after the inner loop.
Complexity:O(n²) time from the triangular letter count; O(1) extra space for nested loops.
One line: for i from the top letter down to 'A', print i for every j from top down to i, then println.
Frequently Asked Questions
Program 9 uses A, BB, CCC, ... (letters increase). Program 10 uses E, DD, CCC, ... (letters decrease) with the same growing repeat counts.
On the 4th row the outer-loop letter is B, and the inner loop runs four times, printing B each time.
j only controls how many times the loop runs. Printing i keeps the row the same letter; printing j would change letters across the row.
With for (char j = top; j >= i; j--), when i is near the top the range is short; as i moves toward A the range lengthens, so repeat counts grow 1, 2, 3, …
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 1+2+…+n = 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 A.
🤔
Did you know?
This pattern is the reverse of Program 9: row widths still grow 1, 2, 3, …, but letters run backward (E, then D, then C, …). Print the outer loop letter inside the inner loop so each row stays uniform.