logo Practice-It logo

tokenStats

Language/Type: Java file processing Scanner
Author: Marty Stepp

Write a method named tokenStats that accepts as a parameter a Scanner containing a series of tokens. It should print out the sum of all the tokens that are legal integers, the sum of all the tokens that are legal real numbers but not integers, and the total number of tokens of any kind. For example, if a Scanner called data contains the following tokens:

3 3.14 10 squid 10.x 6.0

Then the call of tokenStats(data); should print the following output:

integers: 13
real numbers: 9.14
total tokens: 6

If the Scanner has no tokens, the method should print:

integers: 0
real numbers: 0.0
total tokens: 0
Type your solution here:


This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.