Question: 1. (20 pts) In the following code inside a try block, what kind of object is passed to the Scanner constructor? Scanner file = new

1. (20 pts) In the following code inside a try block, what kind of object is passed to the Scanner constructor?

Scanner file = new Scanner (

new File (data.txt));

2. (20 pts) What is the output of this code sequence?

Scanner parse = new Scanner (A B C D);

while (parse.hasNext())

System.out.print(parse.next());

3. (20 pts) What is the output of the following code?

try

{

Scanner file = new Scanner(new File(data.txt));

int n = 0;

while (file.hasNext())

{

String s = file.nextLine();

if (s.equals(A))

n++;

}

System.out.println(The value of n is +n);

file.close();

}

catch(IOException ioe)

{

ioe.printStackTrace();

}

4. (40 pts) You coded the following class:

try

{

Scanner file = new Scanner( new File(data.txt));

String s = file.nextLine();

} catch (ArithmeticException ae)

{

System.out.println(ae.getMessage());

}

Explain what the problem is and how to fix it.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!