Bird
0
0

You want to write a Kotlin script that reads a command line argument and prints it. Which snippet correctly accesses the first argument in script mode?

hard📝 Application Q8 of 15
Kotlin - Basics and JVM Runtime
You want to write a Kotlin script that reads a command line argument and prints it. Which snippet correctly accesses the first argument in script mode?
Aprintln(input[0])
Bprintln(arguments[0])
Cprintln(argv[0])
Dprintln(args[0])
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kotlin script argument variable

    Kotlin scripts use 'args' array for command line arguments.
  2. Step 2: Verify correct syntax to access first argument

    Access first argument with args[0].
  3. Final Answer:

    println(args[0]) -> Option D
  4. Quick Check:

    Script args accessed via args array [OK]
Quick Trick: Use 'args' array to access script command line arguments [OK]
Common Mistakes:
MISTAKES
  • Using incorrect variable names like arguments or argv
  • Confusing script args with REPL variables
  • Trying to read input without args array

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes