Hollow Concentric Octagon Hybrid (Stars + Alphabets)

This program prints hollow concentric octagons alternating stars and alphabets.

Problem Statement

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

Source Code

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

Program Output

* * * * * * * 
A A       A A 
*   *   *   * 
D     D     D 
*   *   *   * 
F F       F F 
* * * * * * * 

Explanation

The same border-and-diagonal octagon condition applies, but the row-parity check i%2==0 decides whether a marked cell prints a star or an alphabet, mixing two symbol types across the octagon outline.

Quick Links to Explore