Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Kotlin!
fun parseInt(str: String): Int? { return str.toIntOrNull() } fun printProduct(arg1: String, arg2: String) { val x = parseInt(arg1) val y = parseInt(arg2) // Using `x * y` yields error because they may hold nulls. if (x != null && y != null) { // x and y are automatically cast to non-nullable after null check println(x * y) } else { println("either '$arg1' or '$arg2' is not a number") } } fun main(args: Array<String>) { printProduct("6", "7") printProduct("a", "7") printProduct("a", "b") }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
?. in Kotlin
Arun1
Floor 1 -> Smith
iya
KotlineMerg
Haha
degerliilkornek
My script1
KotlinCopy
Rotate array
Please log in to post a comment.