Skip to content

Commit e84302d

Browse files
committed
feat: Print square star pattern using nested loops based on user input
🧠 Logic: - Read input `n` from the user to determine size of the square. - Outer loop (`i`) runs from 1 to `n` to handle rows. - Inner loop (`j`) runs from 1 to `n` to print `*` in each column of the row. - After each inner loop completes, print a newline to format square shape. Signed-off-by: Somesh diwan <[email protected]>
1 parent 8535012 commit e84302d

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
public class NestedLoopCC2 {
44
public static void main(String[] args) {
55
Scanner scanner = new Scanner(System.in);
6+
System.out.println("Enter a Number: ");
67
int n = scanner.nextInt();
78

8-
for(int i =1; i <=n; i++)
9-
{
10-
for(int j = 1; j<= n; j++)
11-
{
9+
for(int i =1; i <=n; i++) {
10+
for(int j = 1; j<= n; j++) {
1211
System.out.print("* ");
1312
}
1413
System.out.println();
1514
}
16-
1715
}
1816
}

0 commit comments

Comments
 (0)