Symmetric Decreasing Alphabet Square in Java

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

What You’ll Learn

This pattern is built row by row. The outer letter stays high on the borders (E), while the center drops down to A.

We create symmetry by printing a left half (E down to A) and then a mirrored right half (B up to E).

⭐ Pattern Output

Output for 5 rows (a space after each letter):

Output
E E E E E E E E E
E D D D D D D D E
E D C C C C C D E
E D C B B B C D E
E D C B A B C D E
1

Java Program (Fixed A–E)

Two symmetric scans per row with the same j > i check.

Java
public class Main {
    public static void main(String[] args) {
        int i, j;
        int k = 69; // 'E'

        for (i = k; i >= 65; i--) {
            for (j = k; j >= 65; j--) {
                if (j > i) System.out.print((char) j + \" \");
                else System.out.print((char) i + \" \");
            }
            for (j = 66; j <= k; j++) {
                if (j > i) System.out.print((char) j + \" \");
                else System.out.print((char) i + \" \");
            }
            System.out.println();
        }
    }
}

🧠 How It Works

1

k is the top letter

With k = 'E', the border stays E and the pattern grows inward as rows descend.

Top
2

Outer i controls the row floor

i goes E down to A. Each row prints either j (outer shell) or i (row floor) based on a simple comparison.

Row
3

Two symmetric scans

Left half prints EA. Right half prints BE so the center is not duplicated.

Mirror
4

The core rule

If the column letter j is greater than the row floor i, print j, otherwise print i.

j>i
=

Border + interior

High letters stay on the outside, and lower letters fill the interior as i decreases.

2

Variation — User Input

Let the user choose the top letter count. We clamp rows to 1–26 and compute top as 'A' + rows - 1.

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: ");
        int rows = sc.nextInt();

        rows = Math.max(1, Math.min(rows, 26));
        char top = (char) ('A' + rows - 1);

        for (char i = top; i >= 'A'; i--) {
            for (char j = top; j >= 'A'; j--) {
                System.out.print((j > i ? j : i) + " ");
            }
            for (char j = 'B'; j <= top; j++) {
                System.out.print((j > i ? j : i) + " ");
            }
            System.out.println();
        }

        sc.close();
    }
}

💡 Tips for Enhancement

Try These

  • Remove the trailing space after the last character on each row
  • Use lowercase by shifting the start to 'a'
  • Try a numeric variant (same logic with numbers)

Avoid

  • Starting the second half at 'A' (duplicates the center)
  • Letting rows exceed 26 without handling non-letter output

Key Takeaways

1

Each cell prints either the border letter j or the row floor i.

2

Two mirrored loops build the left and right halves.

3

Start the second half at B to avoid duplicating the center.

4

O(n²) total work for n letters.

❓ Frequently Asked Questions

Because the left half already printed the center A. Starting at B avoids duplicating it.
Yes. Replace \" + \" \" with just the character, but update the sample output to match.
O(n²) because there are n rows and each row prints O(n) cells.

More Java alphabet patterns

Patterns with symmetry often reuse the same rule on both halves of the row.

All Alphabet Patterns →
Did you know?

This is the same idea as a concentric square: the outer ring stays at the maximum letter, while inner rings decrease toward the center.

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