An increasing-start alphabet triangle keeps a fixed end letter on the right and moves the start letter one step later each row — so the left edge slides inward.
Remember
Rule: for start letter i from A to last,
print i through last
ABCDE
BCDE
CDE
DE
E ← 5 rows (right edge fixed at E)
Same widths as Program 5 (5, 4, 3, 2, 1), but Program 5 shortens the end while restarting at A. Here the start advances and the end stays put. Compare also with Program 3, which grows into the same right edge.
Approach
How to Solve It
Two ways to emit the same shape — start with nested char loops, then optionally shorten with substring.
Method
Idea
Best for
Nested char loops
Outer = advancing start; inner = start..end
Learning, interviews, exams
top.substring(i)
Drop one left letter each row from a fixed prefix
Shorter demos once loops click
Pseudocode
Pseudocode
end = lastLetter
for start from 'A' to end:
for ch from start to end:
print ch (no newline)
print newline
Cheat sheet
Goal
Pattern
Advance start letter
for (char i = 'A'; i <= end; i++)
Print i..end
for (char j = i; j <= end; j++) System.out.print(j);
End the row
System.out.println();
End letter from rows
char end = (char)('A' + rows - 1);
One-line row shortcut
System.out.println(top.substring(i)); while i advances
Print letters without a newline, then end the row once.
Try it
Live Preview
Change the row count and the increasing-start triangle updates instantly — capped at 26 letters (A–Z).
Whole numbers from 1 to 26. Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · 15 letters
ABCDE
BCDE
CDE
DE
E
Trace
Worked Walkthrough — rows = 4
Trace each outer-loop start letter as i advances from 'A' to 'D' with end fixed at 'D'.
Start i
Inner j
Printed row
Letters
'A'
A..D
ABCD
4
'B'
B..D
BCD
3
'C'
C..D
CD
2
'D'
D..D
D
1
Total letter prints: 4 + 3 + 2 + 1 = 10 = 4×5/2 — same triangular count as Programs 1 and 5.
Code
Java Programs
Three complete programs: fixed end letter, Scanner input, and a substring shortcut. Use View Output to reveal sample results.
Example 1 — Fixed end at 'E'
Hard-coded end letter — outer loop advances the start; inner loop prints i..E.
Java
public class IncreasingStartAlphabet {
public static void main(String[] args) {
for (char i = 'A'; i <= 'E'; i++) {
for (char j = i; j <= 'E'; j++) {
System.out.print(j);
}
System.out.println();
}
}
}
Output
ABCDE
BCDE
CDE
DE
E
How It Works
1. Outer loop picks the start letter.i runs from 'A' to 'E' — longest row first.
2. Inner loop starts at i. For each start, j runs from i to 'E', so the row is i..E.
3. Print letters, then break the line.System.out.print(j) stays on the row; println() after the inner loop starts the next (shorter) row.
When i = 'A' you get ABCDE; when i = 'E' you get E.
Example 2 — User Input Version
Read the row count at runtime. Prefer validating with hasNextInt and clamping to 26 (shown in the tip below).
Java
import java.util.Scanner;
public class IncreasingStartAlphabetInput {
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 end = (char)('A' + rows - 1);
for (char i = 'A'; i <= end; i++) {
for (char j = i; j <= end; j++) {
System.out.print(j);
}
System.out.println();
}
sc.close();
}
}
Output (when user enters 4)
Enter the number of rows: 4
ABCD
BCD
CD
D
How It Works
1. Prompt and read. Ask for a row count, then read an int with Scanner.
2. Map rows to an end letter.end = (char)('A' + rows - 1) — for rows = 4, end is 'D'.
3. Same advance core. Only the source of end changes — the print logic matches Example 1.
4. Safer input tip.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 — substring(i)
Drop one left letter each row from a fixed prefix — same shape, no explicit inner letter loop.
Java
public class IncreasingStartAlphabetSubstring {
public static void main(String[] args) {
int rows = 5;
String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String top = letters.substring(0, rows);
for (int i = 0; i < rows; i++) {
System.out.println(top.substring(i));
}
}
}
Output
ABCDE
BCDE
CDE
DE
E
How It Works
1. Build the first row.top = letters.substring(0, rows) is ABCDE when rows = 5.
2. Slice from index i.top.substring(0) is the full row; substring(1) drops A; and so on.
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.
j = 'A'
Program 5 by mistake
If the inner loop starts at 'A' instead of i, you print ABCDE, ABCD, … Use for (char j = i; …).
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.
Wrong end
Off-by-one end letter
Use (char)('A' + rows - 1). Forgetting - 1 pushes the end past the intended letter.
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 — start and end coincide. A good sanity check.
Bad input
Check hasNextInt
nextInt() throws on letters — prefer hasNextInt() and require 1–26.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(rows²)
O(1)
Substring (Example 3)
O(rows²)
O(rows) for the prefix and temporary row strings
Total letters = n + (n - 1) + … + 1 = n(n + 1)/2 — quadratic in n. Same totals as Programs 1 and 5.
Remember
Key Takeaways
Rule: advance start letter i; print i through a fixed end each row.
vs Program 5: same widths — here the left edge moves; there the right edge moves.
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 'A' to the end letter, print i through that end, then println.
Frequently Asked Questions
The outer loop picks the starting letter (A, then B, then C…). The inner loop prints from that start up to a fixed end letter. Each row drops the leftmost character and becomes shorter.
Because the inner loop always stops at the same end letter ('E'), so the last printed character is fixed on the right.
Program 5 restarts each row at A and shortens the end letter (ABCDE, ABCD, …). Program 6 shifts the start letter forward each row while keeping the same end letter (ABCDE, BCDE, …).
Program 3 grows while starting earlier (E, DE, CDE). This pattern shrinks while starting later (ABCDE, BCDE, CDE). Both keep a fixed right edge at the top letter.
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²) for n rows, because total printed characters are n(n+1)/2.
Yes. Take letters.substring(0, rows), then print top.substring(i) while i runs from 0 to rows-1. Nested char loops are better for learning; substring is a handy shortcut later.
Check sc.hasNextInt() before sc.nextInt(), require n ≥ 1, and cap at 26 so bad input does not walk past Z.
🤔
Did you know?
Each row starts one letter later but always ends at the same letter. For 5 rows: ABCDE, BCDE, CDE, DE, E. Same widths as Program 5, but the left edge moves instead of the right.