Hollow Concentric Diamond Hybrid (Stars + Alphabets)

This program prints hollow concentric diamonds alternating stars and alphabets.

Problem Statement

Write a Java program that prints concentric hollow diamonds where odd rows have stars and even rows have alphabets.

Source Code

1 public class HollowConcentricDiamondHybrid {
2 public static void main(String[] args) {
3 int n = 6;
4 for(int i=1; i<=n; i++) {
5 for(int j=i; j<n; j++) System.out.print(" ");
6 for(int j=1; j<=2*i-1; j++) {
7 if(j==1 || j==2*i-1) {
8 if(i%2==1) System.out.print("*");
9 else System.out.print((char)('A'+i-1));
10 } else System.out.print(" ");
11 }
12 System.out.println();
13 }
14 for(int i=n-1; i>=1; i--) {
15 for(int j=i; j<n; j++) System.out.print(" ");
16 for(int j=1; j<=2*i-1; j++) {
17 if(j==1 || j==2*i-1) {
18 if(i%2==1) System.out.print("*");
19 else System.out.print((char)('A'+i-1));
20 } else System.out.print(" ");
21 }
22 System.out.println();
23 }
24 }
25 }

Program Output

     *     
    B B    
   *   *   
  D     D  
 *       * 
F         F
 *       * 
  D     D  
   *   *   
    B B    
     *     

Explanation

The hollow diamond boundary logic from both halves is combined with a row-parity check, so odd rows print stars at boundaries while even rows print an alphabet derived from the row index, forming a hollow diamond hybrid.

Quick Links to Explore