Exam 11: Inputoutput and Exception Handling

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

Complete the code fragment below, which is designed to throw an exception if String variable accountNumber has more than seven characters. If (accountNumber.length() > 7) { ___________________________________________ }

(Multiple Choice)
4.8/5
(28)

Insert the missing code in the following code fragment. This fragment is intended to read floating-point numbers from a text file. Scanner in = new Scanner(. . .); While (____________) { Double hoursWorked = in.nextDouble(); System.out.println(hoursWorked); }

(Multiple Choice)
4.9/5
(35)

Select an appropriate expression to complete the header for the method below. public void openFile(String inputFile) ______________________________ { File theFile = new File(inputFile); Scanner data = new Scanner(theFile); // additional statements to input data from file }

(Multiple Choice)
4.8/5
(27)

Select an expression to complete the program segment below, which displays an error message and terminates normally if String variable accountNumber does not contain an integer value. try { Int number = Integer.parseInt(accountNumber); } Catch ( ________________________ ) { System.out.println("Account number is not an integer value"); }

(Multiple Choice)
4.9/5
(42)

You have opened a command prompt window and you have entered the following: java myProg Bob Smith Which of the following statements is correct?

(Multiple Choice)
4.9/5
(31)

Which of the following statements about reading and writing text files is correct?

(Multiple Choice)
4.8/5
(38)

Which of the following objects should be used for reading from a text file?

(Multiple Choice)
4.9/5
(41)

Your program must read in an existing text file. You want the program to terminate if any exception related to the file occurs. Which of the following indicates the correct code for the main method?

(Multiple Choice)
4.9/5
(37)

Consider the following code snippet: try { PrintWriter outFile = new PrintWriter(filename); WriteData(outputFile); } Catch (IOException exception) { ) . . } Finally { OutputFile.close(); } What is wrong with this code?

(Multiple Choice)
4.8/5
(40)

Consider the following code snippet. Scanner in = new Scanner(. . .); While (in.hasNextLine()) { String input = in.nextLine(); } Which of the following statements about this code is correct?

(Multiple Choice)
4.9/5
(31)

The Scanner class's ____ method is used to specify a pattern for word boundaries when reading text.

(Multiple Choice)
4.9/5
(51)

Which of the following statements about exception reporting is true?

(Multiple Choice)
4.8/5
(41)

Consider the following code snippet: Scanner in = new Scanner(. . .); Int ageValue = in.nextInt(); If there is no integer number appearing next in the input, what will occur?

(Multiple Choice)
4.9/5
(29)

If the current method in a program will not be able to handle an exception, what should be coded into the method?

(Multiple Choice)
4.8/5
(34)

Insert the missing code in the following code fragment. This fragment is intended to read binary data. public static void main(String[] args) throws IOException { String address = "http://horstmann.com/bigjava.gif"; URL imageLocation = new URL(address); InputStream in = _________; ) . . }

(Multiple Choice)
4.8/5
(36)

Consider the following code snippet: public double[] readInputFile(String filename) throws IOException { File inputFile = new File(filename); Scanner in = new Scanner(inputFile); Try { ReadData(in); Return data; } Finally { InputFile.close(); } } Which of the following statements about this method's code is correct?

(Multiple Choice)
4.8/5
(39)

Insert the missing code in the following code fragment. This fragment is intended to read an input file named dataIn.txt and write to an output file named dataOut.txt. public static void main(String[] args) throws FileNotFoundException { String inputFileName = "dataIn.txt"; String outputFileName = "dataOut.txt"; File inputFile = _________________; Scanner in = new Scanner(inputFile) ) . . }

(Multiple Choice)
4.8/5
(40)

Consider the following code snippet: Scanner in = new Scanner(. . .); In)useDelimiter("[^0-9]+"); What characters will be ignored and not read in using this code?

(Multiple Choice)
4.9/5
(34)

Which of the following statements about a PrintWriter object is true?

(Multiple Choice)
4.8/5
(31)

Select the missing expression in the code fragment below. The method should continue to prompt the user for a valid integer value until one is entered. The method returns the final value entered. public static int getAge() { Boolean done = false; Scanner console = new Scanner(System.in); Int value = 0; While (!done) { Try { System.out.print("Please enter your age in years: "); Value = console.nextInt(); Done = true; } ______________________ { System.out.println("Invalid value. Try again."); Console.nextLine(); } } Return value; }

(Multiple Choice)
4.9/5
(39)
Showing 61 - 80 of 109
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)