Skip to content

Commit b0ace1a

Browse files
committed
feat: Draw a rectangle using nested loops and conditionals
🧱 Logic: - Outer loop iterates over rows; inner loop over columns - Print '-' for top and bottom borders - Print '|' for left and right borders - Fill the rest with spaces to form a hollow rectangle. Signed-off-by: Somesh diwan <[email protected]>
1 parent 2214964 commit b0ace1a

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed
Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
public class NestingLoopsAndConditionals
2-
{
3-
public static void main(String[] args)
4-
{
1+
public class NestingLoopsAndConditionals {
2+
public static void main(String[] args) {
53
System.out.println("Behold my rectangle!");
64
int rows = 6, columns = 34;
7-
for (int x = 1; x <= rows; x++)
8-
{
9-
for (int y = 1; y <= columns; y++)
10-
{
5+
for (int x = 1; x <= rows; x++) {
6+
for (int y = 1; y <= columns; y++) {
117
if (x == 1 || x == rows)
128
System.out.print("-");
139
else if (y==1 || y==columns)
@@ -18,4 +14,4 @@ else if (y==1 || y==columns)
1814
System.out.println();
1915
}
2016
}
21-
}
17+
}

0 commit comments

Comments
 (0)