Exam 11: Inputoutput and Exception Handling
Exam 1: Introduction98 Questions
Exam 2: Using Objects76 Questions
Exam 3: Implementing Classes103 Questions
Exam 4: Fundamental Data Types125 Questions
Exam 5: Decisions120 Questions
Exam 6: Loops128 Questions
Exam 7: Arrays and Array Lists118 Questions
Exam 8: Designing Classes95 Questions
Exam 9: Inheritance101 Questions
Exam 10: Interfaces85 Questions
Exam 11: Inputoutput and Exception Handling109 Questions
Exam 12: Object-Oriented Design104 Questions
Exam 13: Recursion110 Questions
Exam 14: Sorting and Searching109 Questions
Exam 15: The Java Collections Framework110 Questions
Exam 16: Basic Data Structures104 Questions
Exam 17: Tree Structures110 Questions
Exam 18: Generic Classes75 Questions
Exam 19: Graphical User Interfaces76 Questions
Exam 20: Streams and Binary Inputoutput82 Questions
Exam 21: Multithreading82 Questions
Exam 22: Internet Networking74 Questions
Exam 23: Relational Databases75 Questions
Exam 24: XML74 Questions
Exam 25: Web Applications75 Questions
Select questions type
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);
Free
(Multiple Choice)
4.9/5
(40)
Correct Answer:
B
Which of the following statements about using the PrintWriter object is correct?
Free
(Multiple Choice)
4.9/5
(32)
Correct Answer:
C
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);
) . .
}
Free
(Multiple Choice)
4.7/5
(36)
Correct Answer:
D
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?
(Multiple Choice)
4.9/5
(33)
When writing a method, which of the following statements about exception handling is true?
(Multiple Choice)
4.7/5
(39)
Which of the following statements about exception handling is recommended by the textbook?
(Multiple Choice)
4.7/5
(37)
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);
}
(Multiple Choice)
4.7/5
(31)
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?
(Multiple Choice)
4.8/5
(35)
Which Java class implements a file dialog box for selecting a file by a program with a graphical user interface?
(Multiple Choice)
4.8/5
(43)
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?
(Multiple Choice)
5.0/5
(34)
Consider the following code snippet: public static void main(String[] args) throws IOException
Which of the following statements about this code is correct?
(Multiple Choice)
4.8/5
(33)
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?
(Multiple Choice)
4.9/5
(47)
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?
(Multiple Choice)
4.8/5
(31)
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?
(Multiple Choice)
4.7/5
(43)
Assume that inputFile is a Scanner object used to read data from a text file which contains a number of lines. Each line contains an arbitrary number of words, with at least one word per line. Select an expression to complete the following code segment, which prints the last word in each line. while (inputFile.hasNextLine())
{
String word = "";
String line = inputFile.nextLine();
Scanner words = new Scanner(line);
While (_________________)
{
Word = words.next();
}
System.out.println(word);
}
(Multiple Choice)
4.9/5
(46)
You wish to use the Scanner class's nextInt() method to read in whole numbers. To avoid exceptions that would occur if the input is not a whole number, you should use the ____ method before calling nextInt.
(Multiple Choice)
4.7/5
(37)
Insert the missing code in the following code fragment. This code is intended to open a file and handle the situation where the file cannot be found. public void String readFile() throws IOException
{
File inputFile = new File(. . .);
Scanner in = new Scanner(inputFile);
Try
{
While (in.hasNext())
{
) . .
}
}
Finally
{
___________________
}
}
(Multiple Choice)
4.8/5
(34)
Consider the following code snippet: Scanner in = new Scanner(. . .);
In)useDelimiter("[^A-Za-z]+");
What characters will be ignored and not read in when using this code?
(Multiple Choice)
4.8/5
(40)
Which method of an exception object will retrieve a description of the exception that occurred?
(Multiple Choice)
4.7/5
(30)
Showing 1 - 20 of 109
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)