Skip to content

Instantly share code, notes, and snippets.

@un-ro
Created April 28, 2021 08:09
Show Gist options
  • Select an option

  • Save un-ro/34bac7c93d7de63b297a003a19bccaf1 to your computer and use it in GitHub Desktop.

Select an option

Save un-ro/34bac7c93d7de63b297a003a19bccaf1 to your computer and use it in GitHub Desktop.
// Fizz Buzz
fun fizzBuzz(start: Int, end: Int){
for (i in start..end) {
if ((i % 3 == 0) && (i % 5 == 0)) {
print("Fizz Buzz, ")
} else if (i % 3 == 0) {
print("Fizz, ")
} else if (i % 5 == 0) {
print("Buzz, ")
} else {
print("$i, ")
}
}
}
fun main() {
fizzBuzz(1, 30)
}
@un-ro
Copy link
Author

un-ro commented Feb 14, 2023

// Only using 'When'
for (i in 1..100) {
        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