0
Has someone solved the continuous input challenge from lesson?
I got okay result, from case one e two, but three and four are hidden the correct outputs and I dunno what I did wrong: fun main(args: Array<String>) { var bb = 0 var aa = 0 while(true) { var input = readLine()!!.toInt() if (input == 0){ break } bb = input } if(bb>9){ aa = bb%10 } else if (bb < -9){ aa = bb%10 } else{ aa = bb } println(aa) }
5 Respostas
+ 3
I can't find this Kotlin challenge.
Can you post it's location or the details of the challenge
+ 2
Thanks Simba
+ 1
Hey Rik, thanks for the help. Really there's no need to the 'aa' variable, but still the case 3 and 4 didn't get correctly and unfortunately and I can see what's the expected output.
The code I found on the link shared here on this Q&A, it works. I'll try understand why it works and mine not afterwards.
fun main(args: Array<String>) {
var i= 0
while(true) {
var input = readLine()!!.toInt()
i++
if(input==0) break
}
println(i-1)
}
0
João Batista dos Santos Sousa
I was getting an error stating that variable aa was redundant.
try this tweak
fun main(args: Array<String>) {
var bb = 0;
//var aa = 0;
while(true) {
var input = readLine()!!.toInt()
if (input == 0){
break
}
bb = input
}
if(bb>9){
bb = bb%10
} else if (bb < -9){
bb = bb%10
}
println(bb)
}