0
How does byte work in this code
Java data types https://code.sololearn.com/cvr4lL627XXz/?ref=app
6 Respostas
+ 3
It is true that the byte ranges from -128 to 127. But it is going nowhere close to infinity. This is called overflowing, when 'by' reaches 127 it is greater than 0. So the loop continues and 'by' is incremented by 1. Now 'by' becomes -128, yes 127+1=-128. So -128 is less than 0 and the loop breaks. The value of 'by' is then printed.
Print the value of 'by' inside the loop before incrementing to see how it works.
+ 3
Do you know bytes range from -128 to 127. So your code is going infinity after reaching 127 it again goes to -128 which is smaller than 0
+ 2
My pleasure alagammai uma
+ 1
Avinesh thank u
+ 1
alagammai uma You're welcome
0
Atul thanks