1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| fun main() { println("hello World!") print("11") println("12")
val valInt = 1 val valInt2: Int valInt2 = 2
var varInt: Int varInt = 2 varInt = 3
val yourWord = readln()
val sum = sum(1, 2) println(sum) printSum(2, 3)
var rectangle: Rectangle = Rectangle(5.0, 4.0) println(rectangle.perimeter)
var a = 1 val s1 = "a is $a" a = 2 val s3 = "${s1.replace("is", "was")}, but now is $a" println(s3)
val maxOf = maxOf(1, 2) println(maxOf) fun maxOf2(a: Int, b: Int) = if (a > b) a else b val maxOf2 = maxOf2(1, 2) println(maxOf2)
getStringLength("ss")
val items = listOf("apple", "banana", "kiwifruit") for (index in items.indices) { println("item at $index is ${items[index]}") }
fun describe(obj: Any): String = when (obj) { 1 -> "One" "Hello" -> "Greeting" is Long -> "Long" !is String -> "Not a string" else -> "Unknown" }
val describe = describe("Hello") println("뭐냐? $describe 이거다")
val x = 10 val y = 9 if (x in 1..y + 1) { println("fint in range") }
val list = listOf("a", "b", "c") if (2 !in 0..list.lastIndex) { println("-1 is out of range") } if (list.size - 1 !in list.indices) { println("list size is out of valid list indices range, too") }
when { "orange" in items -> print("오랜지") "apple" in items -> print("사과") }
val fruits = listOf("banana", "avocado", "apple", "kiwifruit") fruits.filter { it.startsWith("a") } .sortedBy { it } .map { it.uppercase() } .forEach { println(it) }
printProduct("a", "b") }
fun parseInt(str: String): Int? { return str.toIntOrNull() }
fun printProduct(arg1: String, arg2: String) { val x = parseInt(arg1) val y = parseInt(arg2)
if (x != null && y != null) { println(x * y) } else { println("'$arg1' or '$arg2' is not a number") } }
fun sum(a: Int, b: Int): Int { return a + b }
fun printSum(a: Int, b: Int) { println("sum of $a and $b is ${a + b}") }
fun maxOf(a: Int, b: Int): Int { if (a > b) { return a } else { return b } }
fun getStringLength(obj: Any): Int? { if (obj !is String) return null return obj.length }
|