Lesson 13 of 34

Nested Loops: Star PatternsNested Loops: Star Patterns

10 min 30 XP

ஒரு loop-க்குள் இன்னொரு loop வைக்கலாம். வெளி loop வரிகளை (rows), உள் loop ஒவ்வொரு வரியிலும் உள்ள எழுத்துகளை (columns) கட்டுப்படுத்தும். Pattern கேள்விகள் campus interviews-ல் அடிக்கடி வரும்.

You can put one loop inside another. The outer loop controls the rows and the inner loop prints each row's characters. Pattern questions are very common in campus interviews.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

Example: edit me and press Run

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.

ஒவ்வொரு row-லும் எத்தனை space, எத்தனை star என்று ஒரு சிறிய அட்டவணை எழுதிப் பாருங்கள். Pattern தானாகப் புரியும்.

Write a small table of how many spaces and stars each row has. The loop limits become obvious.

Challenge

+30 XP

n-ஐப் படித்து இந்த number triangle-ஐ print செய்யுங்கள் (n = 4): 1 1 2 1 2 3 1 2 3 4

Read n and print this number triangle (n = 4): 1 1 2 1 2 3 1 2 3 4

Output Loading Java (first time takes a few seconds)
Press Run to see the result here.