0

Why output is "127"

public class Program { public static void main(String[] args) { byte x =-128; --x; System .out .println (x); } }

8th May 2020, 6:56 AM
Dasarath Singh
2 Respostas
+ 6
The byte primitive data type has a range from -128 to +127. If you decrease the minimum amount then it overflows to the maximum. https://www.w3schools.com/java/java_data_types.asp
8th May 2020, 7:19 AM
Tibor Santa
Tibor Santa - avatar
+ 4
That's because of 'overflow'. Each number type has a certain range of numbers it can contain, depending on the allocated memory. If the number goes out of range, it jumps to the other end of the spectrum.
8th May 2020, 7:20 AM
HonFu
HonFu - avatar