Question: import java.io.*; import java.util.*; public class Q7 { public static void main(String args[]) throws FileNotFoundException { int a=0, b=0; double c=0; File datafile = new
import java.io.*;
import java.util.*;
public class Q7 {
public static void main(String args[]) throws FileNotFoundException {
int a=0, b=0;
double c=0;
File datafile = new File("info.txt");;
Scanner fileInput = new Scanner(datafile);;
while (fileInput.hasNext()) {
if (fileInput.hasNextInt()) {
a += fileInput.nextInt(); }
else if (fileInput.hasNextDouble()) {
c += fileInput.nextDouble();
while (fileInput.hasNextDouble()) {
a += fileInput.next().indexOf("."); } }
else { b += fileInput.next().length();; } }
System.out.println("a=" + a); System.out.println("b=" + b); System.out.println("c=" + c); } }
Let file info.txt be as follows:
Chuck
45
3.6
Sue
3
Determine the code output Console:
a=48
b=8
c=3.6
I need help deciphering this problem more clearly, I understand where C prints out as 3.6, but am a little confused on A and B. I thought A would be 45 since it is the next int, but in the else-if while loop it asks for the position of "." which is 8. Could someone please help explain why the console outputs 48 and 8 for A and B respectively?
Thank you in advanced!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
