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!"); }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter14: Exception Handling
Section: Chapter Questions
Problem 1TF
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT