A reverse-starting-letter alphabet triangle grows leftward: each row begins one letter earlier, but letters along the row still run forward to a fixed top.
Remember
Rule: start letter moves top→A; print forward to top
E
DE
CDE
BCDE
ABCDE ← top = 'E' (5 rows)
Mixes Program 1 (forward run) with Program 2 (moving start). The right edge stays fixed at top on every row.
Approach
How to Solve It
Two ways to emit the same shape — nested char loops, or a growing suffix of a fixed alphabet string.
Method
Idea
Best for
Nested char loops
Outer = start letter; inner = start up to top
Learning, interviews, exams
Alphabet suffix
Slice the last r letters of "ABC…top"
Shorter demos once loops click
Pseudocode
Pseudocode
top = 'A' + rows - 1
for start from top down to 'A':
for ch from start up to top:
print ch (no newline)
print newline
Print letters without a newline, then end the row once.
Try it
Live Preview
Change the row count and the reverse-start forward triangle updates instantly — every row ends at the same top letter.
Whole number from 1 to 10. Tap a chip or type a count — the preview redraws as you go.
Live result5 rows · top E · 15 letters
E
DE
CDE
BCDE
ABCDE
Trace
Worked Walkthrough — Top = E (5 rows)
Trace each start letter and the resulting forward suffix.
i (start)
Inner range
Printed row
E
E..E
E
D
D..E
DE
C
C..E
CDE
B
B..E
BCDE
A
A..E
ABCDE
Row lengths are 1, 2, 3, 4, 5. The right edge is always E.
Code
Java Programs
Three complete programs: fixed top E, row-count input, and spaced letters. Use View Output to reveal sample results.
Example 1 — Fixed Top E
Outer loop chooses the first letter on the row; inner loop prints forward up to 'E'.
Java
public class ReverseStartTriangle {
public static void main(String[] args) {
for (char i = 'E'; i >= 'A'; i--) {
for (char j = i; j <= 'E'; j++) {
System.out.print(j);
}
System.out.println();
}
}
}
Output
E
DE
CDE
BCDE
ABCDE
How It Works
1. Outer loop moves the start.i runs from 'E' down to 'A' — one start letter per row.
2. Inner loop prints forward. For each row, j runs from i up to 'E'. When i = 'C', that prints CDE.
3. Break the line.println() after the inner loop ends the row.
4. Full last row. When i = 'A', the inner loop prints the full forward run ABCDE.
Example 2 — Row Count Input
Read the number of rows and compute top = 'A' + rows - 1. Prefer checking hasNextInt() before nextInt() in real apps.
Java
import java.util.Scanner;
public class ReverseStartTriangleInput {
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);
for (char i = top; i >= 'A'; i--) {
for (char j = i; j <= top; j++) {
System.out.print(j);
}
System.out.println();
}
sc.close();
}
}
Output (when user enters 4)
Enter the number of rows: 4
D
CD
BCD
ABCD
How It Works
1. Scale the top. For 4 rows, top becomes 'D'. Cap rows at 26 so top stays within A–Z.
2. Same core loops. Only the stop letter changes; the start-moves-backward rule is unchanged.
3. Safer input tip. 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 — Spaced Letters
Print a trailing space after each letter so columns are easier to scan.
Java
public class ReverseStartTriangleSpaced {
public static void main(String[] args) {
char top = 'E';
for (char i = top; i >= 'A'; i--) {
for (char j = i; j <= top; j++) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
Output
E
D E
C D E
B C D E
A B C D E
How It Works
1. Same bounds. Loop limits are unchanged — only the printed unit becomes j + " ".
2. Optional trim. Trim trailing spaces later if you need a compact line for grading scripts.
Edge Cases & Pitfalls
Check these before calling the solution done.
Inner j--
Wrong direction on the row
If the inner loop counts down, you get Program 2 (E, ED, EDC). Keep j++ from i to top.
Outer ++
Growing from A instead
If the outer loop runs A..top with the same inner rule, you print Program 1 upside-down. Start at top and go 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 row.
rows = 1
Single A
When top = 'A', you print one row: A. A good sanity check.
rows > 26
Beyond Z
Cap at 26 (or reject) so top stays within A–Z.
Bad input
Check hasNextInt
nextInt() throws on empty or non-numeric text. Prefer hasNextInt() and a clear message.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(n²)
O(1)
Spaced letters (Example 3)
O(n²)
O(1)
For n rows, total letters are 1 + 2 + … + n = n(n + 1)/2 — still quadratic in n.
Remember
Key Takeaways
Rule: start letter moves top → A; print forward to top.
Fixed right edge: every row ends at the same top letter.
Break the row: call println only after the inner loop.
Complexity:O(n²) time; O(1) extra space.
One line: for each start from top down to A, print that letter forward up to top.
Frequently Asked Questions
The outer loop moves the starting letter from E down to A. The inner loop always prints forward from that start letter up to E (or top), so the last character remains E on every row.
Program 2 prints letters descending along the row (E, ED, EDC). This program prints forward along the row (E, DE, CDE) while only the row’s first letter moves backward.
Program 1 always starts at A and grows the end letter (A, AB, ABC). This pattern grows the start letter backward while keeping the right edge fixed at top.
Yes. Read rows from the console and set top = (char)('A' + rows - 1). Then loop i from top down to 'A' and print j from i up to top.
O(n²) for n rows, because the total printed letters are 1+2+...+n = n(n+1)/2.
Check sc.hasNextInt() before sc.nextInt(), require n ≥ 1, and cap at 26 so the top letter stays within A–Z.
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.
Yes. Use 'a' as the base: top = (char)('a' + rows - 1), then loop the same way with j++ up to top.
🤔
Did you know?
This triangle changes only the starting letter of each row (E, D, C, …), while letters along the row still increase forward. In the 5-row example, every row ends at E, producing E, DE, CDE, BCDE, ABCDE.