Hollow Concentric Triangle Hybrid

This program prints hollow concentric triangles alternating stars and alphabets.

Problem Statement

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

Source Code

1 public class HollowConcentricTriangleHybrid {
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 || i==n) {
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 }
15 }

Program Output

     *     
    B B    
   *   *   
  D     D  
 *       * 
FFFFFFFFFFF

Explanation

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

Quick Links to Explore