第 5 行和第 6 行错误。
Kotlin:类型不匹配:推断类型为 String 但预期为 String.Companion
class Robot (name: String,color :String) {
var roboName= String
var roboColor= String
init {
this.roboName=name
this.roboColor=color
}
fun makeBed()
{
println("I will make your bed.")
}
}
fun main(args: Array<String>){
var robot1=Robot("Robot1","Black")
println(robot1.roboName)
println(robot1.roboColor)
robot1.makeBed()
}
Run Code Online (Sandbox Code Playgroud) fun main(args:Array<String>)
{
println("Enter values of c and d")
var c:String= readLine()!!
var d:String= readLine()!!
try
{
division(c,d)
} catch (e:Exception)
{
println("Exception Occured")
e.printStackTrace()
}
}
fun division(a:Int,b:Int){
println(a/b)
}
Run Code Online (Sandbox Code Playgroud)
错误:(6, 17) Kotlin:类型不匹配:推断的类型是字符串,但需要 Int 错误:(6, 19) Kotlin:类型不匹配:推断的类型是字符串,但需要 Int
kotlin ×2