Symmetric Alphabet, Star Center

What You’ll Learn
Build rows that read the same forwards and backwards on the letters, with * filling the gap in the middle as the row shortens.
The classic reference form uses ASCII values (65.. 69) and prints ** pairs in the middle to keep symmetry.
⭐ Pattern Output
For n = 5:
ABCDEEDCBA
ABCD**DCBA
ABC****CBA
AB******BA
A********AComplete Java Program (Reference Logic)
Three zones per row: left letters, star gap, right letters. The star loop prints ** (two stars) per iteration, so the center width grows by 2 each row.
public class Main {
public static void main(String[] args) {
int i, j, k, m;
for (i = 69; i >= 65; i--) {
for (j = 65; j <= i; j++) {
System.out.print((char) j);
}
for (k = i; k < 69; k++) {
System.out.print("**");
}
for (m = i; m >= 65; m--) {
System.out.print((char) m);
}
System.out.println();
}
}
}🧠 How It Works
Outer i = 'E' .. 'A'
The end letter shrinks each row: E, D, C, B, A.
Left half j = 'A' .. i
Print a prefix from A up to the current row end letter.
Star gap "**"
The loop runs 69 - i times and prints two stars per step, so stars = 2*(69 - i).
Right half m = i .. 'A'
Mirror the left side by printing descending letters.
Characters per row
For n = 5, each row prints 10 characters total (letters + stars + letters).
Variation — User Input (General n)
Use top = base + rows - 1. The star count becomes 2*(top - i), so it grows by 2 each row as the letter range shrinks. 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, k, m;
for (i = top; i >= base; i--) {
for (j = base; j <= i; j++) {
System.out.print((char) j);
}
for (k = i; k < top; k++) {
System.out.print("**");
}
for (m = i; m >= base; m--) {
System.out.print((char) m);
}
System.out.println();
}
sc.close();
}
}💡 Tips for Enhancement
Try These
- Swap
*for spaces or.for a softer look - Trace one row: track the last printed letter and the star count
2*(top - i) - Clamp
rowssotopstays within'A'..'Z'
Avoid
- Printing
"*"once per iteration if you want the exact reference output (it uses"**") - Using
2 * ifor stars instead of2 * (top - i)(center width flips)
Key Takeaways
Three zones per row: ascending letters, stars, descending letters.
The middle grows by 2 stars each row: 2*(top - i).
For fixed n, each row prints 2n total characters in this pattern family.
Overall time O(n²) for n rows.
❓ Frequently Asked Questions
i == top, the gap is 2*(top - i) = 0. The two halves meet directly: ABCDE + EDCBA.Math.max(1, …) the variation never uses less than 1 row. Always validate or clamp user input in your own programs.More Java alphabet patterns
Mixing letters and stars is the same idea as hollow or diamond star programs — split each row into zones.
For fixed n, each row prints exactly 2n characters total (letters + stars + letters). That makes it easy to center-align the pattern in monospaced output if you want to extend it.
12 people found this page helpful
