Kotlin Intro

Hello World

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 my.program.MainKt

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.
Same as 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:
1 2
b(1) is greater than a(2)
a  = 1, b = 2, max value = 2

For !! Operator Please check Null Safety.

Faci un comentariu sau dai un răspuns?

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *

Acest site folosește Akismet pentru a reduce spamul. Află cum sunt procesate datele comentariilor tale.