Bird
0
0

You want to print the price with a dollar sign, for example: $20. Which Kotlin string correctly shows the dollar sign before the number stored in price?

hard📝 Application Q15 of 15
Kotlin - Variables and Type System
You want to print the price with a dollar sign, for example: $20. Which Kotlin string correctly shows the dollar sign before the number stored in price?
Aprintln("$price")
Bprintln("\$price")
Cprintln("$\$price")
Dprintln("\$$price")
Step-by-Step Solution
Solution:
  1. Step 1: Understand escaping dollar sign in Kotlin strings

    To print a literal dollar sign, use \$ to escape it.
  2. Step 2: Combine escaped dollar sign with variable

    "\$$price" prints a literal $ followed by the value of price.
  3. Final Answer:

    println("\$$price") -> Option D
  4. Quick Check:

    Escape $ with \$ to print it literally [OK]
Quick Trick: Escape $ as \$ to print dollar sign literally [OK]
Common Mistakes:
MISTAKES
  • Not escaping $ prints variable name or causes error
  • Using $\$ instead of \$$
  • Confusing escape sequences

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes