Skip to content

Instantly share code, notes, and snippets.

View gyugyu90's full-sized avatar
🎯
Focusing

Kyuhyeok Park gyugyu90

🎯
Focusing
  • Seoul, Republic of Korea
View GitHub Profile
val jane = User("Jane", 35)
val (name, age) = jane // 구조 분해
println("$name, $age세") // Jane, 35세
val jack = User(name = "Jack", age = 1)
val olderJack = jack.copy(age = 2)
data class Person(val name: String) {
var age: Int = 0
}
fun main() {
val person1 = Person("John")
val person2 = Person("John")
person1.age = 10
person2.age = 20
data class Person(val name: String) {
var age: Int = 0
}
val rectangle = Rectangle(5.0, 2.0)
val triangle = Triangle(3.0, 4.0, 5.0)
fun main() {
val fruits = listOf("banana", "avocado", "apple", "kiwifruit")
fruits
.filter { it.startsWith("a") }
.sortedBy { it }
.map { it.toUpperCase() }
.forEach{ println(it) }
}
fun main() {
val items = setOf("apple", "banana", "kiwifruit")
when {
"orange" in items -> println("juicy")
"apple" in items -> println("apple is fine too")
}
}
fun main() {
val items = listOf("apple", "banana", "kiwifruit")
for (item in items) {
println(item)
}
}
fun main() {
for (x in 1..10 step 2) {
print(x) //13579
}
println()
for (x in 9 downTo 0 step 3) {
print(x) //9630
}
}
fun main() {
for (x in 1..5) {
print(x)
}
}