Exercises


Note

The solutions to these exercises are in Appendix B.

  1. In this chapter, you learned about the following line:

    String s = "C:my_backup\temporary\news";

    What does the following code print out?

    String s = "C:my_backup\temporary\news"; System.out.println("***\n" + s + "***");

    What is the moral of this exercise?

  2. The code examples in the "Writing and Reading Data" section defined an int called i, a float called f, a double called d, and so on. But the long was called n, which breaks the pattern. You might have expected the long to be called l. Why do you think this was not done?

  3. Write a program that creates a file containing 5,000 random doubles that are >= 0 and <200.

  4. Write a program that verifies the file you created in the previous exercise. Your program should read the 5,000 doubles, making sure that each falls within the proper range. Your program should also make sure the file contains exactly 5,000 longs.

  5. Look up the API documentation for the java.io.File class. An instance of this class contains information about an individual file. One of the methods of the class tells you the length in bytes of a file. Use this method to determine the number of bytes in the file you created in Exercise 3.




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