This file contains hidden or 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
val a: Int = 1 // μ μΈκ³Ό λμμ ν λΉ | |
val b = 2 // 'Int'νμ μ΄ μΆλ‘ λ¨ | |
val c: Int // ν λΉλμ§ μλλ€λ©΄ νμ μ μ§μ ν΄μ€μΌ ν©λλ€ | |
c = 3 // μ μΈν λ€μμ ν λΉνκΈ° |
This file contains hidden or 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
val PI = 3.14 // μ΅μμ λ 벨 λ³μ | |
var x = 0 | |
fun incrementX() { | |
x += 1 | |
} | |
fun main() { | |
var x = 5 // 'Int' νμ μ΄ μΆλ‘ λ¨ | |
x += 1 |
This file contains hidden or 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
var a = 1 // μ½λμ λμ ν μ€μ§λ¦¬ μ£Όμμ λ¬ μ μμ΅λλ€. | |
/* | |
μ¬λ¬ λΌμΈμ μ£Όμμ μΈ κ²½μ° | |
μ΄μκ°μ΄ μ΄κ³ λ«μ΅λλ€. | |
*/ |
This file contains hidden or 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() { | |
var a = 1 | |
// ν νλ¦Ώ λ΄μ λ³μλ₯Ό λ£κ±°λ | |
val s1 = "a is $a" | |
a = 2 | |
// λ³μλ₯Ό νμ©ν ννμμ λ£μ μλ μμ΅λλ€. | |
val s2 = "${s1.replace("is", "was")}, but now is $a" | |
println(s2) // a was 1, but now is 2 |
This file contains hidden or 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 maxOf(a: Int, b: Int): Int { | |
if (a > b) { | |
return a | |
} else { | |
return b | |
} | |
} |
This file contains hidden or 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 maxOf(a: Int, b: Int) = if (a > b) a else b |
This file contains hidden or 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 parseInt(str: String): Int? { | |
// ... | |
} |
This file contains hidden or 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 parseInt(str: String): Int? { | |
return str.toIntOrNull() | |
} | |
fun printProduct(arg1: String, arg2: String) { | |
val x = parseInt(arg1) | |
val y = parseInt(arg2) | |
// x + yλ λ μ€ nullμΈ κ°μ κ°μ§ κ²μ΄ μμ κ²½μ° μλ¬κ° λ μ μμ΅λλ€. |
This file contains hidden or 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 parseInt(str: String): Int? { | |
return str.toIntOrNull() | |
} | |
fun printProduct(arg1: String, arg2: String) { | |
val x = parseInt(arg1) | |
val y = parseInt(arg2) | |
if (x == null) { |
This file contains hidden or 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 getStringLength(obj: Any): Int? { | |
if (obj is String) { | |
// λΈλ‘μ μ κ·Όνκ² λλ©΄ String νμ μΌλ‘ μμ νκ² νλ³νλ¨ | |
return obj.length | |
} | |
// νλ³νλλ λΈλ‘ λ°μμλ Any νμ μ κ·Έλλ‘ μ¬μ© | |
return null | |
} |