|
Note | The solutions to these exercises are in Appendix B. |
What happens when a comment appears inside a literal string? (Recall from Chapter 2 that a literal string is a run of text enclosed between double quotes.) What would the following line of code do?
System.out.println("A /* Did this print? */ Z");
Write a program that includes this line. Does the program print the entire literal string, or does it just print "A Z"?
What is the value of ~100? What is the value of ~-100? First try to figure it out, and then write a program to print out the values. (Hint: You can figure it out without using pen and paper if you remember something that was discussed in Chapter 2.)
Write a program that prints out the following values:
32 << 3
32 >> 3
32 >>> 3
-32 << 3
-32 >> 3
-32 >>> 3
What are the values of the following expressions? First do the computations mentally. Then write a program to verify your answer.
false & ((true^(true&(false|!(true|false))))^true) true | (true^false^false^true&(false|!(true&true)))
The following expression looks innocent:
boolean b = (x == 0) | (10/x > 3);
You can assume x is an int. Write a program that prints out the value of this expression for the following values of x: 5, 2, 0. What goes wrong? (You will see a failure message that you might not be familiar with, because we have not introduced it yet. Don't worry – just try to understand the general concept.) How can you make the code more robust by adding a single character to the expression?
The 32-bit float type is wider than the 64-bit long type. How can a 32-bit type be wider than a 64-bit type?
Write a program that contains the following two lines:
byte b = 6; byte b1 = -b;
What happens when you try to compile the program?
|