Skip to main content

Practice · 2 of 5

Build output in a loop

CHALLENGE
Difficulty: beginner+25 XP

Implement String evens(int n): return the even numbers 2, 4, ..., 2n joined by ", " — e.g. evens(3) returns "2, 4, 6". Accumulate into a String; add ", " **before** each item except the first.

Back to lesson: Practice: Loop rep