Hybrid Concentric Circle Grid
This program approximates concentric circles using numbers, alphabets, and stars.
Problem Statement
Write a Java program that prints concentric circles approximated in text with hybrid symbols in a 9x9 grid.
Source Code
| 1 | public class HybridConcentricCircleGrid { |
| 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) System.out.print("* "); |
| 8 | else if(dist==2) System.out.print((char)('A'+i) + " "); |
| 9 | else if(dist==0) System.out.print(i+1 + " "); |
| 10 | else System.out.print(" "); |
| 11 | } |
| 12 | System.out.println(); |
| 13 | } |
| 14 | } |
| 15 | } |
Program Output
* * *
A A
* *
B B
5 5
C C
* *
D D
* * *
Explanation
The Manhattan-distance ring logic distinguishes three distances explicitly, printing a star at the outer ring, an alphabet at the middle ring, and a number at the center, so three symbol types layer the concentric rings.