+ 2

Need help what is the error in my code?

When I am executing this code the output is "Time limited Exceed" Why please help! https://code.sololearn.com/czvZS6LKM0oR/?ref=app

5th Sep 2017, 5:31 PM
Aditya
Aditya - avatar
4 Antworten
+ 4
And now you've changed your code and moved the * 100 up to Math.random() which will also solve the casting problem, but you also changed the text output in the else block and have forgotten to add back your break statement, once again creating an infinite loop, but this time with some output.
5th Sep 2017, 5:52 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
You have an infinite loop. r is cast to an int prior to r being multiplied by 100. Making dod always equal to 0 which is less than 21 so the continue statement is ran. To fix surround r*100 in parenthesis. dod=(int)(r*100);
5th Sep 2017, 5:43 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
thx I will add
5th Sep 2017, 5:55 PM
Aditya
Aditya - avatar
+ 1
Done!
5th Sep 2017, 5:58 PM
Aditya
Aditya - avatar