+ 2
Kotlin Practice Digit sum question
Please check my code and tell me what is the problem. fun main(args: Array<String>) { var num = readLine()!!.toInt() var sum = 0 while (num == 0){ var i = num % 10 sum = sum + i num = num - i num = num / 10 } println(sum) } Example question. 124 Example answer. 7 Output answer. 0
2 Respuestas
+ 3
replace "while (num == 0)" by "while (num != 0)" ^^
+ 3
Condition should be while <num> not equal to zero.
Also, `num = num - i` is not necessary.