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!"); }
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
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT