Square of Stars
This program prints a square of stars.
Problem Statement
Write a Java program that prints a 4x4 square of stars.
Source Code
| 1 | public class SquareStars { |
| 2 | public static void main(String[] args) { |
| 3 | for(int i=1; i<=4; i++) { |
| 4 | for(int j=1; j<=4; j++) { |
| 5 | System.out.print("* "); |
| 6 | } |
| 7 | System.out.println(); |
| 8 | } |
| 9 | } |
| 10 | } |
Program Output
* * * * * * * * * * * * * * * *
Explanation
The outer loop runs 4 times to control rows while the inner loop runs 4 times to print 4 stars per row, so each row prints identical stars forming a uniform square grid of 16 stars.