Answer:
// Program is written in Java Programming Language
// Comments are used for explanatory purpose
// Import input/output and utility libraries
import java.io.*;
import java.util.*;
Declare class/
public class Numbers {
// Main method goes here
public static void main(String[] args) throws FileNotFoundException
{
// Read input from text file evenFile.txt; Assume file name is evenFile.txt
Scanner input = new Scanner(new File("evenFile.txt"));
// Call static method here
evenNumbers(input);
}
// Static method evenNumbers begins here
public static void evenNumbers(Scanner input)
{
// Declare and initialise Variables
String Nums = input.nextLine(); // Read all number in txt file
Scanner numbers = new Scanner (Nums);
int count = 0; // Number count
int evens = 0; // Even count
int sum = 0; // Summation of numbers
// Check if number is integer. If yes, continue the below operations
while (numbers.hasNextInt())
{
int num = numbers.nextInt();
count++;
sum = sum + num;
if(num % 2 == 0) // check for even
{
evens++;
}
}
System.out.println("Total numbers= " + count); // Print total number
System.out.println("Sum of numbers = " + sum); // Print summation of numbers
System.out.println("Total evens = " + evens); // Print total even
//Calculate and print percentage of even number
double percent = ((double)evens/count)*100.0);
System.out.println("Percent of even number = " +percent);
}
}
// End of program