0
0
Kotlinprogramming~10 mins

Main function as entry point in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the main function in Kotlin.

Kotlin
fun [1]() {
    println("Hello, Kotlin!")
}
Drag options to blanks, or click blank then click option'
Amain
Bstart
Crun
Dbegin
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name like 'start' or 'run' instead of 'main'.
2fill in blank
medium

Complete the code to define the main function with command-line arguments.

Kotlin
fun main([1]: Array<String>) {
    println("Arguments count: ${args.size}")
}
Drag options to blanks, or click blank then click option'
Aarguments
Bargs
Cparams
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Using a parameter name not matching the usage inside the function.
3fill in blank
hard

Fix the error in the main function declaration.

Kotlin
fun [1](args: Array<String>) {
    println("Welcome!")
}
Drag options to blanks, or click blank then click option'
AMain
Bstart
Cmain
DmainFunction
Attempts:
3 left
💡 Hint
Common Mistakes
Capitalizing the function name as 'Main' instead of 'main'.
4fill in blank
hard

Fill both blanks to create a main function that prints each argument.

Kotlin
fun [1]([2]: Array<String>) {
    for (arg in [2]) {
        println(arg)
    }
}
Drag options to blanks, or click blank then click option'
Amain
Bargs
Cparams
Dinput
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatch between parameter name and loop variable.
Using incorrect function name.
5fill in blank
hard

Fill all three blanks to create a main function that prints the number of arguments and the first argument if present.

Kotlin
fun [1]([2]: Array<String>) {
    println("Number of args: $[3].size")
    if ([3].isNotEmpty()) {
        println([3][0])
    }
}
Drag options to blanks, or click blank then click option'
Amain
Bargs
Dparams
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the parameter and the variable accessing size.
Incorrect function name.