Star-Numeric-Alphabet Lattice

This program prints a lattice alternating stars, numbers, and alphabets.

Problem Statement

Write a Java program that prints a 6x6 lattice alternating stars, numbers, and alphabets cyclically.

Source Code

1 public class StarNumericAlphabetLattice {
2 public static void main(String[] args) {
3 int n=6, num=1;
4 char ch='A';
5 for(int i=0; i<n; i++) {
6 for(int j=0; j<n; j++) {
7 int mod=(i+j)%3;
8 if(mod==0) System.out.print("* ");
9 else if(mod==1) System.out.print(num++ + " ");
10 else {
11 System.out.print(ch + " ");
12 ch++;
13 if(ch>'Z') ch='A';
14 }
15 }
16 System.out.println();
17 }
18 }
19 }

Program Output

* 1 A * 2 B 
C * 3 D * 4 
E F * 5 G * 
6 H I * 7 J 
K 8 L M * 9 
N O 10 P Q * 

Explanation

The diagonal-based value (i+j)%3 cycles through star, number, and alphabet in that order, producing a lattice where the three symbol types repeat along anti-diagonal bands across the grid.

Quick Links to Explore