Back to questions
JuniorTheoryCommon
What does the program print?
fun main() {
val a = 2
val b = 3
println("$a + $b = ${a + b}")
}2 + 3 = 5
- Expecting
5 = 5: outside${}the+is a plain character in the string, so$a + $bprints the two values with a+between them. - Expecting
$a + $b = 5: a$followed by a name is replaced by that variable's value; the braces are needed only for an expression likea + b.
- What does
println("$a$b")print? - How do you print the
$sign itself, for example in a price?