Exercises


Note

The solutions to these exercises are in Appendix B.

  1. According to Table 2.1, the maximum values for the byte and short data types are 127 and 32767, respectively. Use the Twos-Complement Lab animated illustration to verify this. Which byte and short bit patterns produce the maximum values? In general, which bit pattern produces the maximum value for a two's complement number of N bits?

  2. According to Table 2.1, the minimum values for the byte and short data types are -128 and -32768, respectively. Use the Twos-Complement Lab animated illustration to verify this. What byte and short bit patterns produce the minimum values? In general, what bit pattern produces the minimum value for a two's complement number of N bits?

  3. Launch the Twos-Complement Lab animated illustration by typing java TwosCompLab, set the data type to int, and set all the bits to 1. Then set the three bits on the right to 0. Compute the value. Do the same for the byte and short data types. What do you observe?

  4. Launch the Floating-Point Lab animated illustration by typing java floating.FloatFrame. Set the rightmost bit to 1 and all other bits to 0. The value represented is 1.4E-45. Try changing various bits' values by clicking on them. Can you create a value that is smaller than 1.4E-45 but still greater than 0?

  5. Write a Java application that declares and assigns values to three int variables named x, y, and z. Print out all three values, separated by commas, on a single line.

  6. White space means spaces, tabs, and line-break characters. Type in the VerySimple application from this chapter (reproduced below) and experiment with inserting white space. Does anything change during compilation or execution if you insert extra spaces between public and class? What if you insert a line break between public and class? Can you find any adjacent words or symbols such that inserting white space between them changes compilation or execution?

    public class VerySimple {   public static void main(String[] args)   {     double age;     age = 123.456;   } } 




Ground-Up Java
Ground-Up Java
ISBN: 0782141900
EAN: 2147483647
Year: 2005
Pages: 157
Authors: Philip Heller

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net