+ 1
what's wrong with the code?
fun main(args: Array<String>) { var age=readLine()!!.toInt() var token=readLine()!!.toFloat() var result= when{ age>token -> "You are very poor" age<token -> "You are very wealthy" else -> "Average level" } println(result) }
6 Respostas
+ 3
Your code is ok. But there was a missing CR or new line at the end of one or more lines.
I've corrected this. And show you how to print it directly w/o additionel result variable
fun main(args: Array<String>) {
val age=readLine()!!.toInt()
val token=readLine()!!.toFloat()
println ( when {
age>token -> "You are very poor"
age<token -> "You are very wealthy"
else -> "Average level"
} )
}
https://code.sololearn.com/cN5em9uLHySf/?ref=app
+ 2
время Ч Kotlin has that keyword 'when' that can successfully replace an if-else structure.
The code seems legit. But you didn't said what is the error.
+ 1
You try to compare an Int to a Float. Kotlin might not like that. What is the error?
0
That is, here you need to write code through the else if?
0
Sorry, I'm just studying and I don't understand what my problem is
0
thanks a lot