Zum Hauptinhalt springen
•
Sichere ProgrammierungDeepCompass: The IIT Madras BS Degree AI Study Workbench(05.10.2026 um 05:41 Uhr)
•
Sichere ProgrammierungWhen Should a UK Freelancer Register for VAT?(05.10.2026 um 05:44 Uhr)
•
Sichere ProgrammierungClaude Max Plan Price 2026: Max 5x vs Max 20x, 5x Wins(05.10.2026 um 05:44 Uhr)
•
Sichere ProgrammierungI built Pocket Tutor, a local Gemma study buddy for a friend(05.10.2026 um 05:44 Uhr)
•••
Sichere ProgrammierungKaagaz: I built a private life-admin companion for my parents(05.10.2026 um 05:47 Uhr)
•
Sichere ProgrammierungFixing 413 request entity to large on laravel + nginx(05.10.2026 um 05:48 Uhr)
•••
Sichere ProgrammierungDeepCompass: The IIT Madras BS Degree AI Study Workbench(05.10.2026 um 05:41 Uhr)
•
Sichere ProgrammierungWhen Should a UK Freelancer Register for VAT?(05.10.2026 um 05:44 Uhr)
•
Sichere ProgrammierungClaude Max Plan Price 2026: Max 5x vs Max 20x, 5x Wins(05.10.2026 um 05:44 Uhr)
•
Sichere ProgrammierungI built Pocket Tutor, a local Gemma study buddy for a friend(05.10.2026 um 05:44 Uhr)
•••
Sichere ProgrammierungKaagaz: I built a private life-admin companion for my parents(05.10.2026 um 05:47 Uhr)
•
Sichere ProgrammierungFixing 413 request entity to large on laravel + nginx(05.10.2026 um 05:48 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

Day 1 of #LearnInPublic Java Patterns

🎯 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 Inne…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

🎯 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, we move to the
// next row and give a line break otherwise all stars
// would get printed in 1 line.
System.out.println();
}
}

public static void main(String[] args) {

// Here, we have taken the value of N as 5.
// We can also take input from the user.
int N = 5;
pattern1(N);
}
}






Approach:

There are 4 general rules for solving a pattern-based question:




  • We always use nested loops for printing the patterns. For the outer loop, we count the number of lines/rows and loop for them.

  • Next, for the inner loop, we focus on the number of columns and somehow connect them to the rows by forming a logic such that for each row we get the required number of columns to be printed.

  • We print the ‘*’ inside the inner loop.

  • Observe symmetry in the pattern or check if a pattern is a combination of two or more similar patterns.

  • In this particular problem, we run the outer loop for N times since we have N rows to be printed, the inner loop also runs for N times as we have to print N stars in each row. This way we get a rectangular star pattern (square) with an equal number of rows and columns
    .

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Day 1 of #LearnInPublic Java Patterns

Thematisch verwandte Begriffe: LearnInPublic, Java, Patterns · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Nächster Beitrag