Star-Alphabet Checkerboard
This program prints a checkerboard pattern alternating stars and alphabets.
Problem Statement
Write a Java program that prints a 6x6 checkerboard alternating stars and alphabets.
Source Code
| 1 | public class StarAlphabetCheckerboard { |
| 2 | public static void main(String[] args) { |
| 3 | int n = 6; |
| 4 | char ch = 'A'; |
| 5 | for(int i=0; i<n; i++) { |
| 6 | for(int j=0; j<n; j++) { |
| 7 | if((i+j)%2==0) System.out.print("* "); |
| 8 | else { |
| 9 | System.out.print(ch + " "); |
| 10 | ch++; |
| 11 | if(ch>'Z') ch='A'; |
| 12 | } |
| 13 | } |
| 14 | System.out.println(); |
| 15 | } |
| 16 | } |
| 17 | } |
Program Output
* A * B * C D * E * F * * G * H * I J * K * L * * M * N * O P * Q * R *
Explanation
The condition (i+j)%2==0 alternates star positions in a checkerboard style, while the else branch prints and increments a rotating alphabet character, resetting after 'Z', creating a hybrid star-alphabet checkerboard.