Created
February 27, 2018 14:26
-
-
Save kmdsbng/9467aea93f987dedb3a2a3435c8b11ef 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
//基本問題 | |
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