Bird
0
0

What is the correct way to include a variable name inside a Kotlin string using string templates?

easy📝 Conceptual Q11 of 15
Kotlin - Variables and Type System
What is the correct way to include a variable name inside a Kotlin string using string templates?
Aprintln("Hello, +name+")
Bprintln("Hello, {name}!")
Cprintln("Hello, $name!")
Dprintln("Hello, %name%!")
Step-by-Step Solution
Solution:
  1. Step 1: Understand Kotlin string templates

    Kotlin uses $variable to insert variable values inside strings.
  2. Step 2: Identify correct syntax for variable insertion

    The syntax $name directly inserts the value of name into the string.
  3. Final Answer:

    println("Hello, $name!") -> Option C
  4. Quick Check:

    Use $variable for string templates [OK]
Quick Trick: Use $variable to insert variables inside strings [OK]
Common Mistakes:
MISTAKES
  • Using curly braces without $ like {name}
  • Concatenating with + inside strings
  • Using % signs instead of $

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes