Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Below is my question Then this is my code in eclipse that i used and the output i got The question i have is that
Below is my question
Then this is my code in eclipse that i used and the output i got
The question i have is that if i am right with my output and stuff. I have been seeing people use my code and get
if anyone can help i would be thankful for that. You cannot see it well but it show:
No of tokens that are numbers:6 No of tokens that are not numbers:7 Sum of the numbers: 12.6
my code when running on my laptop i get
No of tokens that are numbers:0 No of tokens that are not numbers:0 Sum of the numbers:0
just want to know what i am doing wrong
Task The task is to read the tokens from a file and print out three values: the number of tokens that are numbers (double s), the number 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 project. To open a file, use a sequence of code like: Scanner in = null; try t in = new scanner (new File ("data.txt")); J catch (FileNotFoundException e) t System.err.println("failed to open data.txt"); System.exit(1); You will need import statements at the top of yourjava file in order 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()) string token = in.next()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started