Services
Discover
Ask a Question
Log in
Sign up
Filters
Done
Question type:
Essay
Multiple Choice
Short Answer
True False
Matching
Topic
Computing
Study Set
Big Java Binder Early Objects
Exam 11: Inputoutput and Exception Handling
Path 4
Access For Free
Share
All types
Filters
Study Flashcards
Practice Exam
Learn
Question 1
Multiple Choice
Assume that inputFile is a Scanner object used to read data from a text file which contains a number of lines. Some lines contain an alphabetic string, while others contain a single integer value. Select an expression to complete the following code segment, which counts the number of integer values in the input file. Int count = 0; While (inputFile.hasNextLine() ) { If (________________________________) { Count++; } InputFile.nextLine() ; } System.out.println(count) ;
Question 2
Multiple Choice
Which of the following statements about using the PrintWriter object is correct?
Question 3
Multiple Choice
Insert the missing code in the following code fragment. This fragment is intended to read an input file named hoursWorked.txt. You want the program to terminate if the file does not exist. public static void main(String[] args) ______________ { File inputFile = new File("hoursWorked.txt") ; Scanner in = new Scanner(inputFile) ; ) . . }
Question 4
Multiple Choice
Consider the following code snippet: try { PrintWriter outputFile = new PrintWriter(filename) ; Try { WriteData(outputFile) ; } Finally { OutputFile.close() ; } } Catch (IOException exception) { ) . . } Which of the following statements about this code is correct?
Question 5
Multiple Choice
When writing a method, which of the following statements about exception handling is true?
Question 6
Multiple Choice
Which of the following statements about exception handling is recommended by the textbook?
Question 7
Multiple Choice
Insert the missing code in the following code fragment. This fragment is intended to read characters from a text file. Scanner in = new Scanner(. . .) ; In) useDelimiter("") ; While (in.hasNext() ) { Char ch = ____________; System.out.println(ch) ; }
Question 8
Multiple Choice
Your program will read in an existing text file. You want the program to terminate if the file does not exist. Which of the following indicates the correct code for the main method header?
Question 9
Multiple Choice
Which Java class implements a file dialog box for selecting a file by a program with a graphical user interface?
Question 10
Multiple Choice
What is the purpose of the throw statement?
Question 11
Multiple Choice
Consider the following code snippet: Scanner in = new Scanner(. . .) ; ) . . If (in.hasNext() ) { Throw new IOException("End of file expected") ; } Which of the following statements about this code is correct?
Question 12
Multiple Choice
Consider the following code snippet: public static void main(String[] args) throws IOException Which of the following statements about this code is correct?
Question 13
Multiple Choice
Consider the following code snippet: If (in.hasNextDouble() ) { Number = in.nextDouble() ; } Result = in.next() ; If the input contains the characters 626.14 average, what values will number and result have after this code is executed?
Question 14
Multiple Choice
Consider the following code snippet written in Java 7: try (PrintWriter outputFile = new PrintWriter(filename) ) { WriteData(outputFile) ; } Which of the following statements about this Java 7 code is correct?
Question 15
Multiple Choice
Consider the following code snippet. File hoursFile = new File("hoursWorked.txt") ; Your program must read the contents of this file using a Scanner object. Which of the following is the correct syntax for doing this?