Hollow Concentric Circle Hybrid (Stars + Alphabets)

This program approximates concentric circles using stars and alphabets.

Problem Statement

Write a Java program that prints concentric circles approximated in text with stars and alphabets in a 9x9 grid.

Source Code

1 public class HollowConcentricCircleHybrid {
2 public static void main(String[] args) {
3 int n = 9;
4 for(int i=0; i<n; i++) {
5 for(int j=0; j<n; j++) {
6 int dist = Math.abs(i-n/2)+Math.abs(j-n/2);
7 if(dist==4 || dist==2) System.out.print("* ");
8 else if(dist==0) System.out.print((char)('A'+i) + " ");
9 else System.out.print(" ");
10 }
11 System.out.println();
12 }
13 }
14 }

Program Output

    * * *     
   *     *    
  *       *   
 *         *  
A           A 
 *         *  
  *       *   
   *     *    
    * * *     

Explanation

The Manhattan-distance ring logic prints stars at the outer two rings, but at the exact center distance (dist==0) it prints an alphabet derived from the row index instead, mixing two symbol types across the rings.

Quick Links to Explore