Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions