+ 1
While loop output.
What is the output of this code? byte by = 0; while(by > 0) by++; System.out.println(by); Why is it equal to -128?
2 Antworten
+ 1
Because of the limits of the type byte: between -128 and 127. The last step when variable by is positive is 127, after incrementing it becomes -128 and the loop stops.
0
The output of your code ist 0. But if you modify the while condition to (by >= 0), it is -128.