Lesson 2.5 · Write it
Fizz check
A whole programPython or Java6 tests, 3 of them hidden
On a phone? Put the lines in order instead
Write a program that reads a whole number (0 or more) and checks whether it is divisible by 3.
- Always print
Number:followed by the number on the first line. - If the number is divisible by 3 (its remainder after dividing by 3 is 0), print
Fizzon the next line. - Spaces at the end of a line are ignored.
Your program is run several times. Only what it prints is checked.
Running Java here comes later. You can put this answer's lines in order instead. You can still write your Java answer (it stays while this page is open) and compare it with our worked solution. Or try this exercise in Python.
Examples
Your program is run 6 times: the 3 examples below, and 3 hidden ones that check the rules above. Only what it prints is checked.
divisible by 3 (rules 1 and 2)
You type
- typed: 9
It prints
Number: 9 Fizz
not divisible by 3 (rule 1 only)
You type
- typed: 7
It prints
Number: 7
zero is divisible by 3 (rules 1 and 2)
You type
- typed: 0
It prints
Number: 0 Fizz