Symmetric Decreasing Alphabet Square in Java

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):
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 EJava Program (Fixed A–E)
Two symmetric scans per row with the same j > i check.
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
k is the top letter
With k = 'E', the border stays E and the pattern grows inward as rows descend.
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.
Two symmetric scans
Left half prints E…A. Right half prints B…E so the center is not duplicated.
The core rule
If the column letter j is greater than the row floor i, print j, otherwise print i.
Border + interior
High letters stay on the outside, and lower letters fill the interior as i decreases.
Variation — User Input
Let the user choose the top letter count. We clamp rows to 1–26 and compute top as 'A' + rows - 1.
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
rowsexceed 26 without handling non-letter output
Key Takeaways
Each cell prints either the border letter j or the row floor i.
Two mirrored loops build the left and right halves.
Start the second half at B to avoid duplicating the center.
O(n²) total work for n letters.
❓ Frequently Asked Questions
A. Starting at B avoids duplicating it.\" + \" \" with just the character, but update the sample output to match.More Java alphabet patterns
Patterns with symmetry often reuse the same rule on both halves of the row.
This is the same idea as a concentric square: the outer ring stays at the maximum letter, while inner rings decrease toward the center.
12 people found this page helpful
