Last active
January 21, 2020 09:17
-
-
Save takenoko-str/2acbf19c1fd792cb7e8c89d3e16e6d9d 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 fizzBuzz(i: Int): String { | |
return when { | |
(i % 5 == 0 && i % 3 == 0) -> "FizzBuzz" | |
(i % 3 == 0) -> "Fizz" | |
(i % 5 == 0) -> "Buzz" | |
else -> i.toString() | |
} | |
} | |
fun main() { | |
for (i in 1..101) { | |
val ret = fizzBuzz(i) | |
println(ret) | |
} | |
} |
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
class FizzBuzz(var num: Int, var result: String) { | |
fun check(n: Int): String { | |
return if (n % this.num == 0) this.result | |
else "$n" | |
} | |
} | |
fun main() { | |
var fizz = FizzBuzz(3, "Fizz") | |
var buzz = FizzBuzz(5, "Buzz") | |
for (i in 1..100) { | |
println(fizz.check(i) + buzz.check(i)) | |
} | |
} |
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() { | |
for (i in 1..101) | |
if (i % 3 == 0 && i % 5 == 0) println("$i: FizzBuzz") | |
else if (i % 3 == 0) println("$i: Fizz") | |
else if (i % 5 == 0) println("$i: Buzz") | |
for (i in 1..10) | |
println("Hello, World") | |
val array = arrayOf("a", "b", "c") | |
for (i in array) println(i) | |
for (i in 10 downTo 0 step 1) println(i) | |
var map = mapOf("1" to "Tanaka", "2" to "sasaki") | |
for ((k, v) in map) println("$k: $v") | |
arrayOf(1, 2, 3, 4, 5).forEach { | |
println(it) | |
} | |
var a: String? = "text message" | |
a = null | |
println(a?.length) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment