Advanced Star-Numeric-Alphabet Lattice Grid
This program prints a grid alternating stars, numbers, and alphabets in advanced cyclic order.
Problem Statement
Write a Java program that prints a 7x7 grid alternating stars, numbers, and alphabets cyclically.
Source Code
| 1 | public class AdvancedStarNumericAlphabetLattice { |
| 2 | public static void main(String[] args) { |
| 3 | int n=7, 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*n+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 G * 5 H * I * 6 J K * 7 L M N O * 8 P Q * 9 R S T * U V W X Y * 10 Z
Explanation
The running row-major index (i*n+j)%3 cycles through star, number, and alphabet consistently across the entire grid regardless of row breaks, producing a continuous three-symbol repeating lattice.