Loading...
Loading...
Loading...
Students sit in a circle and count from 1 to n. Instead of a number divisible by 3 they say Fizz. Instead of a number divisible by 5 they say Buzz. A number divisible by both 3 and 5 becomes FizzBuzz.
Read n and print what each student says, one per line.
FizzBuzz, Fizz, Buzz or the number i.Example
Input
15
Output
1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
15 is divisible by both 3 and 5, so it is FizzBuzz.
Try the problem first. Open one hint at a time.
Loop from 1 to n and use % to test divisibility.
Check "divisible by both" first. Otherwise 15 is caught by the Fizz test and never reaches FizzBuzz.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor