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) }

20th Aug 2021, 9:31 AM
João Batista dos Santos Sousa
5 Respostas
+ 3
I can't find this Kotlin challenge. Can you post it's location or the details of the challenge
20th Aug 2021, 9:52 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Thanks Simba
20th Aug 2021, 10:05 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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) }
21st Aug 2021, 4:31 PM
João Batista dos Santos Sousa
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) }
20th Aug 2021, 10:18 PM
Rik Wittkopp
Rik Wittkopp - avatar