Java Reference
In-Depth Information
different kind than the original one? Which one is caught by a
surrounding catch clause? Write a sample program to try it out.
΢΢ Exercise R11.17. Which exceptions can the next and nextInt methods
of the Scanner class throw? Are they checked exceptions or unchecked
exceptions?
΢΢΢ Exercise R11.18. Suppose the catch clause in the example of Quality
Tip 11.3 had been moved to the inner try block, eliminating the outer
try block. Does the modified code work correctly if (a) the
FileReader constructor throws an exception and (b) the close
method throws an exception?
΢΢ Exercise R11.19. Suppose the program in Section 11.7 reads a file
containing the following values:
0
1
2
3
What is the outcome? How could the program be improved to give a more
accurate error report?
΢΢ Exercise R11.20. Can the readFile method in Section 11.7 throw a
NullPointer-Exception ? If so, how?
Additional review exercises are available in WileyPLUS.
PROGRAMMING EXERCISES
΢΢ Exercise P11.1. Write a program that asks a user for a file name and prints
the number of characters, words, and lines in that file.
523
524
΢΢ Exercise P11.2. Write a program that asks the user for a file name and
counts the number of characters, words, and lines in that file. Then the
program asks for the name of the next file. When the user enters a file that
doesn't exist, the program prints the total counts of characters, words, and
lines in all processed files and exits.
Search WWH ::




Custom Search