0

Why this err is occurring? And how to solve it?

fun man(a:Int):Int{ if(a>3){ return a } } fun main(args: Array<String>) { print(man(6)) }

22nd Jan 2022, 5:00 PM
Annesh Lobdha Singh
Annesh Lobdha Singh - avatar
2 Respuestas
+ 3
If a is not greater than 3 the function does not return a value, but the return type says Int. You need an else part that returns some default value, or make the return type nullable and return null.
22nd Jan 2022, 5:10 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 2
fun man(a:Int):Int{ if(a>3) return a return 0 // A 'return' expression required in a function with a block body } fun main(args: Array<String>) { print(man(6)) }
22nd Jan 2022, 5:22 PM
SoloProg
SoloProg - avatar