Run Code
|
API
|
Code Wall
|
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
1
Rotate array
KotlinCopy
dfg
test.java
GenerateFibonacci47
Calendar 2018 v3.2 (Compressed Coding)
Arun1
Function Call, Arithmetic Operations, User Input and more in Kotlin
My script1
?. in Kotlin