Curly braces showing to remove :Int tag from function

Viewed 24
fun verify(x: Int): Int {
    var a = x
    if(a < 0){
        a += (2*a)
        return a
    }else{
        println("")
    }
}

This last bracket shows an error and says to remove the: Int value after the bracket in fun verify but when I do it it just not returning a value. any alt or solution, please?

1 Answers

In Kotlin, in every case you must return the defined type and if a is a whole number, then it won't return Int, which you don't have to. You must return Int in every case or condition.

Try

fun verify(a: Int): Int {
    if (a<0)
    {
        a+=2*a;
        return a;
    }
    else
    {
        println("");
        return a;
    }
}
Related