Kotlin programs start at the main function. Here is an example of a simple Kotlin “Hello World” program:
When compiled this code will be compiled into a file named after file
name + 'Kt', if your file was named
Main.kt, the compiled code will be in a file name
MainKt. In the above example, the main class to run would be
Main methods using varargs
Main method can also be used with varargs:
Compile and Run Kotlin Code in Command Line
As java provide two different commands to compile and run Java code. Same as Kotlin also provide you different commands.
javac to compile java files.
java to run java files.
kotlinc to compile kotlin files,
kotlin to run kotlin files.
Reading input from Command Line
A simple example of a command-line argument in Kotlin.
The above example most probably will not work in browser so you will have to copy it and run locally.
Here is the output:
Enter two numbers:
b(1) is greater than a(2)
a = 1, b = 2, max value = 2
!! Operator Please check Null Safety.