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
- Read Data Input using Scanner in Kotlin
- Declare Variables In Kotlin
- Double Data type Usage and Type Conversion in Kotlin
- print and println Data Output in Kotlin
- Arithmetic Operators (Mathematical Operators) in Kotlin
- Unary Operators (Sign, Inverts, Increment, and Decrement) in Kotlin
- Printing Variables and Values in Kotlin
- Float Data type Usage and Type Conversion in Kotlin
- Equality Operators (==, !=) and Referential equality Operators (===, !==) in Kotlin
- Long Data type Usage and Type Conversion in Kotlin
- Byte Data type Usage and Type Conversion in Kotlin
- Comparison Operators in Kotlin
- In Operator (in and !in) in Kotlin
- Assignment Operators and Augmented Assignment Operators in Kotlin
- Is Operator (is and !is) in Kotlin
- Read Data Input from Command Line in Kotlin
- Read String Data Input in Kotlin
- Indexed Access Operator [, ] in Kotlin
- Char Data type Usage and Type Conversion in Kotlin
- Elvis Operator (?:) in Kotlin
- Not Null Assertion(!!) Operator in Kotlin
- Logical Operators in Kotlin
- Safe Call Operator (?.) in Kotlin
- Repeat and Its Usage in Kotlin
- Boolean Data type Usage and Type Conversion in Kotlin