Why do I get a strange exception in kotlin on numbers above 2? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 Answers
+ 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