Skip to content

Commit f4647c0

Browse files
committed
feat: Print hollow square star pattern using nested loops
🧠 Logic: - Read integer `n` to define size of the square. - Use nested loops: outer loop for rows (`i`), inner loop for columns (`j`). - Print `*` if the current position is on the border: - First or last row (`i == 1 || i == n`) - First or last column (`j == 1 || j == n`) - Else, print a space to create the hollow effect inside the square. Signed-off-by: Somesh diwan <[email protected]>
1 parent 92a41df commit f4647c0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Section8LoopAB/Loop 2.O/src/NestedLoopIMP.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
public class NestedLoopIMP {
44
public static void main(String[] args) {
5-
System.out.println("Enter a Number: ");
65
Scanner scanner = new Scanner(System.in);
6+
System.out.println("Enter a Number: ");
7+
78
int n = scanner.nextInt();
89

9-
for (int i = 1; i <= n; i++)
10-
{
10+
for (int i = 1; i <= n; i++) {
1111
for (int j = 1; j <= n; j++) {
1212
if (i == 1 || i == n || j == 1 || j == n) {
1313
System.out.print("* ");
@@ -19,4 +19,4 @@ public static void main(String[] args) {
1919
}
2020
scanner.close();
2121
}
22-
}
22+
}

0 commit comments

Comments
 (0)