Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin 类型不匹配:推断类型为字符串,但应为Int_Kotlin - Fatal编程技术网

Kotlin 类型不匹配:推断类型为字符串,但应为Int

Kotlin 类型不匹配:推断类型为字符串,但应为Int,kotlin,Kotlin,错误:6,17 Kotlin:类型不匹配:推断的类型为字符串,但应为Int 错误:6,19 Kotlin:类型不匹配:推断类型为String,但应为Int您正在将字符串传递给只接受Int的方法。用toInt修复: 您正在将字符串传递给只接受int的方法。用toInt修复: c和d是字符串,为什么您希望它们可以作为int?使用parseInt或string.toInt.c和d都是字符串,为什么希望它们可以作为int使用呢?使用parseInt或string.toInt。 fun main(args

错误:6,17 Kotlin:类型不匹配:推断的类型为字符串,但应为Int 错误:6,19 Kotlin:类型不匹配:推断类型为String,但应为Int

您正在将字符串传递给只接受Int的方法。用toInt修复:

您正在将字符串传递给只接受int的方法。用toInt修复:

c和d是字符串,为什么您希望它们可以作为int?使用parseInt或string.toInt.c和d都是字符串,为什么希望它们可以作为int使用呢?使用parseInt或string.toInt。
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)

}
division(c.toInt(), d.toInt())