+ 6
Do the Mathematics in Java Programming overrides the rules of Mathematics?
I have got a rare situation while trying out some examples of infinite loop of my own and found a great confusion for the Mathematicians. Just go throughout the code given below and give the reason why the loop seems to infinite (In the View of Maths) but a finite one. https://code.sololearn.com/cQovo1JMups2/?ref=app
6 odpowiedzi
+ 6
x will take the values 0-127 (that's the capacity of positive values a signed byte can hold), followed by -128 (that's probably because of an overrun because you keep incrementing the byte value beyond its capacity) to -1. So the loop will be executed 255 times.
The same will happen with an integer eventually (in a much larger range of values).
+ 6
Anna Congratulations!
You got it perfectly.
I already know the answer but that's a small test for my friends on SL.
Well done!
+ 5
Anya You are right but not exactly but I would appreciate your try.
+ 4
Anna I imagine that. But your explanation is perfect.
+ 2
Oh. Never Seen that in a code. But I already know what just happened.
Just int instead byte. And see a surprise.
0
yes