我想创建一个函数,允许用户输入2个数字(from
和to
)
但我不希望他们使from
大于to
并且不希望他们输入字符串(我尝试过(如果是(来自字符串),但它不起作用)
fun rand() {
println("Enter First number: ")
var first = readLine()!!.toInt()
println("Enter second number")
val second = readLine()!!.toInt()
if(second - first < 0) {
do {
println("You have to make sure that your first number is larger than the second")
println("Enter your First number: ")
val first = readLine()!!.toInt()
print("Please enter a number smaller than the first number")
val second: Int = readLine()!!.toInt()
} while(first - second < 0)
}
val random = Random().nextInt(second - first) + first
println("Your number is $random")
}