| 3.20 |
What would be printed during execution of the following program?
public class MyClass {
public static void main(String[] args) {
test(1<<32, "1<<32");
test(1<<31, "1<<31");
test(1<<30, "1<<30");
test(1, "1" );
test(0, "0" );
test(-1, "-1" );
}
public static void test(int i, String exp) {
if ((i >> 1) != (i >>> 1)) System.out.println(exp);
}
}
Select the two correct answers.
"1<<32" "1<<31" "1<<30" "1" "0" "-1"
|
| 3.22 |
Given a variable x of type int (which may contain a negative value), which are correct ways of doubling the value of x, barring any wrapping of out-of-range intermediate values?
Select the four correct answers.
x << 1; x = x * 2; x *= 2; x += x; x <<= 1;
|