Type assignment problem
No. 226
Q: |
Consider the following code snippet:
The compiler complains “Required type: byte Provided:
int” with respect to the second line. Why is that although
only Propose a solution solving the issue at the same preserving
the |
A: |
An expression “byte + byte” is of type
The expression a + b of type int may range from -2 * 128 to
2 * 127. Dividing by 2 leaves us with a |