Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

  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 (test.txt));

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

Scanner parse = new Scanner (A 1 B 2 C 3 D);

while (parse.hasNext())

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

  1. (20 pts) What is wrong with following code?

try

{

Scanner file = new Scanner(new File(c:\docs\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();

}

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

try

{

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

String s = file.nextLine();

} catch (FileNotFoundException fnf)

{

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

}

Will this code work correctly? If not how do you 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_2

Step: 3

blur-text-image_3

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago