Hollow Concentric Hexagram of Stars

This program prints a hollow concentric hexagram using stars.

Problem Statement

Write a Java program that prints concentric hollow hexagrams with 7 rows.

Source Code

1 public class HollowConcentricHexagramStars {
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==j || i+j==n-1 || i==0 || i==n-1 || j==0 || j==n-1)
7 System.out.print("* ");
8 else System.out.print(" ");
9 }
10 System.out.println();
11 }
12 }
13 }

Program Output

* * * * * * * 
* *       * * 
*   *   *   * 
*     *     * 
*   *   *   * 
* *       * * 
* * * * * * * 

Explanation

The border and both diagonal conditions are combined identically to the octagon pattern, forming the same star-marked cross-and-border shape used to approximate a hexagram-like star outline.

Quick Links to Explore