Given the following code and a file named "data.txt" whose contents are listed on the next page, show what is printed. Assume that all required imports are defined above the code shown. If an exception occurs, write the word exception for that output line. public class FinalExam4 { public static void main (String[] args) { int i0 = 2, il = 3; double d0 = 2.0, d1 = 3.0, d2 = 4.0; char c0 = '8', cl = 'Z'; String s0 = "", s1 = ""; try { Scanner scan = new Scanner (new File ("data.txt")); d0 = scan.nextDouble(); i0 = scan.nextInt(); c0 = scan.next().charAt (3); s0 = scan.next(); + i0); " + s0); %3D System.out.println(d0 + ": System.out.println(c0 + ": if (scan.hasNextDouble ()) = scan.nextDouble (); d1 if (scan.hasNextInt ()) il = scan.nextInt(); cl = scan.next().charAt(3); scan.nextLine(); // discard newline sl = scan.nextLine (); System.out.println (dl + " System.out.println (cl + ", + il); + sl); %3D d2 = scan.nextDouble(); System.out.println(d2); scan.close (); } catch (Exception e) { System.out.println ("Exception!"); }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Given the following code and a file named "data.txt" whose contents are listed
on the next page, show what is printed. Assume that all required imports are defined above
the code shown. If an exception occurs, write the word exception for that output line.
public class FinalExam4 {
public static void main (String[] args) {
int i0 = 2, il = 3;
double d0 = 2.0, d1 = 3.0, d2 = 4.0;
= 'Z';
= "";
char c0 = '8', cl
String s0
= ""
s1
try {
Scanner scan = new Scanner (new File ("data.txt"));
d0 = scan.nextDouble();
i0
scan.nextInt();
c0
scan.next().charAt (3);
s0 = scan.next ();
System.out.println(d0 + ":
System.out.println(c0 + ":
+ i0);
" + s0);
if (scan.hasNextDouble ())
d1 = scan.nextDouble();
if (scan.hasNextInt ())
il = scan.nextInt();
cl = scan.next().charAt (3);
scan.nextLine (); // discard newline
= scan.nextLine();
s1
System.out.println(dl + "
System.out.println(cl + ",
+ il);
+ s1);
d2 = scan.nextDouble ();
System.out.println(d2);
scan.close ();
} catch (Exception e) {
System.out.println ("Exception!");
}
}
Transcribed Image Text:Given the following code and a file named "data.txt" whose contents are listed on the next page, show what is printed. Assume that all required imports are defined above the code shown. If an exception occurs, write the word exception for that output line. public class FinalExam4 { public static void main (String[] args) { int i0 = 2, il = 3; double d0 = 2.0, d1 = 3.0, d2 = 4.0; = 'Z'; = ""; char c0 = '8', cl String s0 = "" s1 try { Scanner scan = new Scanner (new File ("data.txt")); d0 = scan.nextDouble(); i0 scan.nextInt(); c0 scan.next().charAt (3); s0 = scan.next (); System.out.println(d0 + ": System.out.println(c0 + ": + i0); " + s0); if (scan.hasNextDouble ()) d1 = scan.nextDouble(); if (scan.hasNextInt ()) il = scan.nextInt(); cl = scan.next().charAt (3); scan.nextLine (); // discard newline = scan.nextLine(); s1 System.out.println(dl + " System.out.println(cl + ", + il); + s1); d2 = scan.nextDouble (); System.out.println(d2); scan.close (); } catch (Exception e) { System.out.println ("Exception!"); } }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education