Skip to content

Instantly share code, notes, and snippets.

@chinnonsantos
Created February 20, 2021 23:38
Show Gist options
  • Save chinnonsantos/6ed49ee6a6759cc2e7411f82bd538b23 to your computer and use it in GitHub Desktop.
Save chinnonsantos/6ed49ee6a6759cc2e7411f82bd538b23 to your computer and use it in GitHub Desktop.
fun fizzbuzz(start: Int, end: Int): Unit {
fun isFizz(k: Int): Boolean = k % 3 == 0
fun isBuzz(k: Int): Boolean = k % 5 == 0
for (k in start..end) {
if (isFizz(k) && isBuzz(k))
println("Fizz Buzz")
else if (isFizz(k))
println("Fizz")
else if (isBuzz(k))
println("Buzz")
else
println(k)
}
}
fun main() {
fizzbuzz(start = 1, end = 15)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment