Why do I get a strange exception in kotlin on numbers above 2? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grátis
0

Why do I get a strange exception in kotlin on numbers above 2?

Why does this code only work on the numbers 1 and 2? I’m new to kotlin and I cannot figure out what’s wrong. Thank you https://code.sololearn.com/c424yN7F776U/?ref=app

3rd Jun 2018, 11:51 PM
Rora
2 Respostas
+ 20
It should be product *= i on line 5 since u r using (for loop in kotlin is equivalent to for each loop in other lang) there is no need of nums[i]... if u want to iterate through index of array... for ( i in nums.indices) { product * = nums[i] } u r accessing the elements of the array directly through i... for(i in nums) Your code needs 3 int input on separate line
4th Jun 2018, 3:11 AM
🌛DT🌜
🌛DT🌜 - avatar
0
thanks, it works now
4th Jun 2018, 11:26 AM
Rora