Increasing Start Letter Alphabet Triangle in Java

What You’ll Learn
Each row starts one letter later (A, B, C, ...) but always ends at the same last letter (E in the 5-row example). So the widths are 5, 4, 3, 2, 1.
Compare with program 5, where every row restarts at A and shrinks.
⭐ Pattern Output
When you run the program with rows = 5:
ABCDE
BCDE
CDE
DE
EComplete Java Program
Fixed rows = 5 version. The outer loop selects the starting character and the inner loop prints forward up to 'E'.
public class Main {
public static void main(String[] args) {
int rows = 5;
char endChar = 'E';
for (char start = 'A'; start <= endChar; start++) {
for (char ch = start; ch <= endChar; ch++) {
System.out.print(ch);
}
System.out.println();
}
}
}🧠 How It Works
Pick the row start letter
Outer loop sets start to A, then B, then C, and so on.
Print forward to a fixed end
Inner loop prints from start through endChar (E here), so every row ends at the same letter.
Why the width shrinks
Each time start increases, ch <= endChar spans fewer code points, so the row shortens: five letters for A..E, then four for B..E, and so on.
Between rows
System.out.println() runs after each inner loop so ABCDE, BCDE, … appear on separate lines. The variation replaces literal 'E' with endChar = (char)('A' + rows - 1).
Total work
n(n + 1)/2 characters — O(n²) time, O(1) extra space. Using a char outer loop is idiomatic here and matches the variation.
Variation — User Input Version
Compute endChar = (char)('A' + rows - 1) for any rows (clamped to 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));
char endChar = (char) ('A' + rows - 1);
for (char start = 'A'; start <= endChar; start++) {
for (char ch = start; ch <= endChar; ch++) {
System.out.print(ch);
}
System.out.println();
}
sc.close();
}
}💡 Tips for Enhancement
Try These
- Use lowercase letters by switching to
'a'as the base - Compare with program 3 (reverse start, forward run) for a related fixed-edge pattern
- Right-align lines with leading spaces for a different look
- Print numbers instead of letters to practice similar logic
Avoid
- Letting
rowsexceed 26 without handling wrap-around - Hard-coding end letters when you want a dynamic solution (prefer
endChar) - Forgetting a newline after each row
Key Takeaways
Outer loop controls the starting letter (A, B, C, ...).
Inner loop prints from the start letter up to the same fixed end letter.
Row lengths shrink by one each line: n, n-1, ..., 1.
Total printed characters are n(n+1)/2 so runtime is O(n²).
❓ Frequently Asked Questions
endChar. Only the start moves forward.n rows.Next: Java Alphabet Pattern 7
Continue to Program 7 for the next alphabet pattern in Java.
The right edge stays fixed because the inner loop always ends at endChar—only the start changes each row.
10 people found this page helpful
