New course! Every coder should learn Generative AI!
Try a free lesson0
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
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
0
thanks, it works now