January 2018
Intermediate to advanced
434 pages
14h 1m
English
Create a file and name it ifWithKotlin.kt. You can name it anything; it need not be the same as the class name because it is in Java. Now, to get started, you should always declare the main method because the Java virtual machine starts execution by invoking the main method of the specified class.
The main method is as follows:
fun main(args: Array<String>) { }
fun main(args: Array<String>) { var x:Int if(10>20){ x = 5 } else{ x = 10 } println("$x") }
In this code block, we assign a value to x in the if and else block and then print it.
fun main(args: Array<String>) { var x:Int = if(10>20) 5 else ...Read now
Unlock full access