Question: Task The task is to read the tokenrom a file and print out three values: the number of tokens that are numbers (double s), thenumber

 Task The task is to read the tokenrom a file andprint out three values: the number of tokens that are numbers (double

Task The task is to read the tokenrom a file and print out three values: the number of tokens that are numbers (double s), thenumber of tokens that are not numbers, and the sum of the numbers. For example, if this is the contents of the file being processed 1 2 3 one two three Your program should print out: 6 7 12.6 and nothing else. Assume that the name of the file is data.txt.In Eclipse, the file needs to be in the top directory of the peoject. To open a fie, use a sequence of code like: Scanner in - null; try 1 in ~ new Scanner (new File("data.txt" catch (FileNotFoundException e) System.err.println("failed to open data.txt"); System.exit(l); You will need import statements at the top of your . ava file in onder to use the Scanner and File classes. import java.util.Scanner; import java.io.File; After you are done processing the file, close it in.close(); Reading all the tokens in a file can be done via a loop: while (in.hasNext())f String token- in.next(; One way of converting String to a double is if (new Scanner (token) .hasNextDouble()) System.out.println("It's a double!"; double d = Double. parseDouble (token); 1 else System.out.println("It's not a double

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!