Skip to main content

Practice · 4 of 5

Star triangle (nested loops)

CHALLENGE
Difficulty: beginner+25 XP

Implement static void program(int n) that PRINTS a left-aligned triangle of * characters: row 1 has one star, row n has n stars, each row followed by a newline. program(3) prints "*\n**\n***\n".

Back to lesson: Practice: Practice: Loops