1
votes
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)

}

Error:(6, 17) Kotlin: Type mismatch: inferred type is String but Int was expected Error:(6, 19) Kotlin: Type mismatch: inferred type is String but Int was expected

1
c and d are strings, why do you expect them to be passable as Ints? Use parseInt, or string.toInt.Moira

1 Answers

5
votes

You're passing Strings to a method that only takes Ints. Fix with toInt():

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