println(s"This is a $CarBrand car and it costs $100000.")有错误
时间: 2023-12-14 20:36:20 浏览: 52
idea输入sout无法自动补全System.out.println()的问题
5星 · 资源好评率100%
这行代码的错误是 `$CarBrand` 变量没有被识别。假设 `$CarBrand` 是一个变量,正确的写法应该是使用 `$` 符号来引用它,例如:
```
val CarBrand = "Tesla"
println(s"This is a ${CarBrand} car and it costs $100000.")
```
或者使用字符串拼接的方式:
```
val CarBrand = "Tesla"
println("This is a " + CarBrand + " car and it costs $100000.")
```
阅读全文