Created
January 10, 2022 18:09
-
-
Save sorianog/a6b8de49e2ca9e1850bd21ab0af4f49c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Input: n, number of type Int | |
* Range: 1 to n (inclusive) | |
* | |
* If i is multiple of 3 & 5, print "FizzBuzz" | |
* If i is multiple of 3 only, print "Fizz" | |
* If i is multiple of 5 only, print "Buzz" | |
* If i is not multiple of any (above), print value of i | |
* | |
*/ | |
fun fizzBuzz(n: Int): Unit { | |
for (i in 1..n) { | |
when { | |
(i % 3 == 0 && i % 5 == 0) -> println("FizzBuzz") | |
i % 3 == 0 -> println("Fizz") | |
i % 5 == 0 -> println("Buzz") | |
else -> println("$i") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment