Types and Expressions
Recall that a variable of type byte can store values in the range -128 to 127. The statements
byte x = 127;
x++;
cause a “byte overflow.” Some languages consider this an error, but Java computes x++; by “wrapping around” to negative numbers. For example, 127 + 1 is − 128. Determine the output of the following segment:
1. byte x = 127;
2. int y = x;
3. x++;
4. y++;
5. System.out.println(x);
6. System.out.println(y);
Does changing line 3 to x = x + 1; generate a syntax error? If not, what is the output? Does changing line 4 to y = y + 1; cause an error? If not, what is the output?
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.