Skip to content

Instantly share code, notes, and snippets.

@kmdsbng
Created February 27, 2018 14:26
Show Gist options
  • Save kmdsbng/9467aea93f987dedb3a2a3435c8b11ef to your computer and use it in GitHub Desktop.
Save kmdsbng/9467aea93f987dedb3a2a3435c8b11ef to your computer and use it in GitHub Desktop.
//基本問題
fun main(args: Array<String>) {
(1..100).map{
when {
it % 15 == 0 -> println("FizzBuzz")
it % 3 == 0 -> println("Fizz")
it % 5 == 0 -> println("Buzz")
else -> println(it)
}
}
}
//応用問題
fun main(args: Array<String>) {
(1..100).map{
val containThree = it.toString().split("").contains("3")
val containFive = it.toString().split("").contains("5")
when {
it % 15 == 0 || containFive && containThree -> println("FizzBuzz")
it % 3 == 0 || containThree -> println("Fizz")
it % 5 == 0 || containFive -> println("Buzz")
else -> println(it)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment