Question: Hello, Could you please input validate this code so that the code prints an error message if the user enters in floating point numbers or

Hello,

Could you please input validate this code so that the code prints an error message if the user enters in floating point numbers or characters or ANYTHING but VALID ints? And then could you please post a picture of the output testing it to make sure it works?

* Write a method called evenNumbers that accepts a Scanner * reading input from a file with a series of integers, and * report various statistics about the integers to the console. * Report the total number of numbers, the sum of the numbers, * the count of even numbers and the percent of even numbers. * For example, if the input file contains the following text: * * 5 7 2 8 9 10 12 98 7 14 20 22 * * Then the method should produce the following console output: * * 12 numbers, sum = 214 * 8 evens (66.67%) * */ import java.util.*; import java.io.*; public class Chap6Ex02{ public static void main (String[] args) throws FileNotFoundException{ Scanner input = new Scanner(new File("integers.txt")); evenNumbers(input); } public static void evenNumbers( Scanner inp){ int count = 0; int sum = 0; int evens = 0; while(inp.hasNextInt()){ int num = inp.nextInt(); count++; sum += num; if (num % 2 == 0){ evens++; } } double percent = evens/count * 100; System.out.println(count + " numbers, sum = " + sum); System.out.println(evens + " evens (" + percent + "%)"); } }

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!