Course: Advanced Application Development 1. How do you create a Scanner object s that reads lines from
Question:
Course: Advanced Application Development
1. How do you create a Scanner object s that reads lines from the file in the src folder with file name defined by names.txt?
String fileName = "names.txt"?
a. Scanner s = new Scanner(fileName);
b. Scanner s = new Scanner(new File("src/" + fileName));
c. Scanner s = Scanner.instanceOf(fileName);
d. Scanner s = Scanner.instanceOf(new File("src/" + fileName));
2. How do you create a PrintWriter object pw that writes lines to the file output.txt in the project folder?
a. PrintWriter pw = new PrintWriter(output.txt);
b. PrintWriter pw = new PrintWriter("output.txt");
c. PrintWriter pw = new PrintWriter(File("src/output.txt"));
d. PrintWriter pw = new PrintWriter(new Scanner("src/output.txt");
3. Which statement do you add to the method header when you are creating a new Scanner that reads from a file in that method?
a. catch FileNotFoundException
b. handles FileNotFoundException
c. new FileNotFoundException( )
d. throws FileNotFoundException
4. Which method is automatically called when an object is printed, for example, like this:
System.out.println(p);
a. The constructor for the class.
b. to_s
c. toString
d. __str__
5. Which Java statement is used to create an array of strings consisting of the fields in a comma delimited line?
a. String[ ] fields = line.split(",");
b. String[ ] fields = ",".split(line);
c. String[ ] fields = String.split(line, ",");
d. String[ ] fields = String.split(",", line);
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill