Workbook 5.7
From the Java Bootcamp Resources
, launch Workbook 5.7
.
Fizz Buzz
Your program has to print numbers from 0 to 18.
-
If a number is a multiple of three, mark it: Fizz.
-
If a number is a multiple of five, mark it: Buzz.
-
If a number is a multiple of three and five, mark it: FizzBuzz.
Task 1
Make a for
loop that counts from 0 to 18 and print each number.
>>: 0
>>: 1
>>: ...
>>: 18
Task 2
Set up an if - else if - else
statement.
-
if the number is a multiple of three, mark it:
Fizz
. -
if the number is a multiple of five, mark it:
Buzz
. -
if the number is a multiple of three and five, mark it:
FizzBuzz
.
Hints:
-
A number is a multiple of X if
number
÷X
results in a remainder of zero. -
There are three conditions for Fizz, Buzz, and FizzBuzz. Be careful about their order. If something is FizzBuzz, it also satisfies the conditions for Fizz and Buzz.
Visualizing the Runtime
After you solve this workbook, I still recommend watching the video solution on Udemy.
It will show you how to visualize the runtime using Visual Studio Code.