Symmetric Alphabet, Star Center

Beginner
⏱️ 7 min read
📚 Updated: Aug 2025
🎯 2 Code Examples
Nested Loops

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:

Output
ABCDEEDCBA
ABCD**DCBA
ABC****CBA
AB******BA
A********A
1

Complete 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.

Java
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

1

Outer i = 'E' .. 'A'

The end letter shrinks each row: E, D, C, B, A.

Rows
2

Left half j = 'A' .. i

Print a prefix from A up to the current row end letter.

Up
3

Star gap "**"

The loop runs 69 - i times and prints two stars per step, so stars = 2*(69 - i).

Center
4

Right half m = i .. 'A'

Mirror the left side by printing descending letters.

Down
=

Characters per row

For n = 5, each row prints 10 characters total (letters + stars + letters).

2

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:

Java
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 rows so top stays within 'A'.. 'Z'

Avoid

  • Printing "*" once per iteration if you want the exact reference output (it uses "**")
  • Using 2 * i for stars instead of 2 * (top - i) (center width flips)

Key Takeaways

1

Three zones per row: ascending letters, stars, descending letters.

2

The middle grows by 2 stars each row: 2*(top - i).

3

For fixed n, each row prints 2n total characters in this pattern family.

4

Overall time O(n²) for n rows.

❓ Frequently Asked Questions

When i == top, the gap is 2*(top - i) = 0. The two halves meet directly: ABCDE + EDCBA.
It doubles the center width so the overall row stays symmetric in even steps: 0, 2, 4, 6, 8 stars for five rows.
After Math.max(1, …) the variation never uses less than 1 row. Always validate or clamp user input in your own programs.
O(n²) for n rows.

More Java alphabet patterns

Mixing letters and stars is the same idea as hollow or diamond star programs — split each row into zones.

All Alphabet Patterns →
Did you know?

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.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful