-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFizzBuzz.kt
29 lines (25 loc) · 755 Bytes
/
FizzBuzz.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package other
/**
* The simplest FizzBuzz game
*
* description: the player says numbers in sequence, provided:
* - if the number is divisible by 3 it says fizz
* - if the number is divisible by 5 it says buzz
* - if the number is divisible by both 3 and 5, it says FizzBuzz
* - otherwise, the player calls the number itself
*/
class FizzBuzz {
/**
* determines what to say for a number in the FizzBuzz game
*
* @return returns Fizz, Buzz, FizzBuzz or number
*/
fun compute(number: Int) : String {
return when {
number % 3 == 0 && number % 5 == 0 -> "FizzBuzz"
number % 3 == 0 -> "Fizz"
number % 5 == 0 -> "Buzz"
else -> number.toString()
}
}
}