Day 1 of #LearnInPublic Java Patterns
dev.toΒ·16hΒ·
Discuss: DEV
Flag this post

🎯 Topic: Rectangular Star Pattern πŸ‘¨β€πŸ’» Concepts Used: Nested Loops

I learned how to use nested for loops in Java to print shapes. Outer loop β†’ controls rows Inner loop β†’ controls columns

Here’s my output for N = 4 πŸ‘‡

* * * *
* * * *
* * * *
* * * *

It looks simple β€” but understanding how loops nest inside each other really builds logic skills for future problems.

πŸ’‘ Takeaway: Pattern questions are the best way to train your brain for logical thinking.

class Main {
static void pattern1(int N)
{
// This is the outer loop which will loop for the rows.
for (int i = 0; i < N; i++)
{
// This is the inner loop which here, loops for the columns
// as we have to print a rectangular pattern.
for (int j = 0; j < N; j++)
{
System.out.print("* ");
}

// As soon as N stars are printed...

Similar Posts

Loading similar posts...