Read Data Input from Command Line in Kotlin
Definition
- While compiling and running a Kotlin Program through the command line, the user input can be passed along with the command to run the program.
- The arguments passed are separated by spaces( ).
Compiling the Kotlin Program
kotlinc ProgramName.kt
Running the Kotlin Program
kotlin ProgramNameKt Hey Kotlin Programmer
Here "Hey Kotlin Programmer" is the argument passed. Here, "Hey", "Kotlin" and "Programmer" are separate arguments.
Read Input from Command Line in Kotlin Example Program
// Read Input from Command Line in Kotlin Example Program
// Data Input Kotlin Programs, Basic Kotlin Programs
fun main(args: Array<String>) {
println("Printing all command line arguments: ")
//Printing all arguments passed through command line
for (item in args){
println("Input argument : $item")
}
}
Sample Output
Printing all command line arguments :
Input argument : Hey
Input argument : Kotlin
Input argument : Programmer
Read More Articles
- Declare Variables In Kotlin
- Read Data Input using Scanner in Kotlin
- print and println Data Output in Kotlin
- Double Data type Usage and Type Conversion in Kotlin
- Arithmetic Operators (Mathematical Operators) in Kotlin
- Unary Operators (Sign, Inverts, Increment, and Decrement) in Kotlin
- Equality Operators (==, !=) and Referential equality Operators (===, !==) in Kotlin
- Printing Variables and Values in Kotlin
- Float Data type Usage and Type Conversion in Kotlin
- Long Data type Usage and Type Conversion in Kotlin
- Comparison Operators in Kotlin
- Byte Data type Usage and Type Conversion in Kotlin
- Is Operator (is and !is) in Kotlin
- In Operator (in and !in) in Kotlin
- Char Data type Usage and Type Conversion in Kotlin
- Read Data Input from Command Line in Kotlin
- Assignment Operators and Augmented Assignment Operators in Kotlin
- Indexed Access Operator [, ] in Kotlin
- Read String Data Input in Kotlin
- Short Data type Usage and Type Conversion in Kotlin
- Boolean Data type Usage and Type Conversion in Kotlin
- Logical Operators in Kotlin
- Elvis Operator (?:) in Kotlin
- Repeat and Its Usage in Kotlin
- Safe Call Operator (?.) in Kotlin