+ 2
BagJava
Please can who explain code below Why output - 128 byte b1 = 1; while(b>0) by++; System.out.println(by);
2 Answers
+ 5
Type range overflow. A byte has a range of -128 to 127. When you exceed the range it will wrap around to the opposite end of the range by x amount remaining in the mathematical operation.
I.E. 127 + 1 = -128
-128 - 1 = 127
125 + 5 = -126
etc
+ 2
Byte can held numbers up to 128. After it full it flips the sign. So you get kind of value overflowing.