import java.util.Scanner; public class OddEvenAverage { public static void main(String[] args) { Scanner Scan = new Scanner (OddEvenAverage.class.getResourceAsStream("Numbers.txt")); int numbersCounter = 0; //counts how many numbers in file int osum [] = new int [25]; //sum of all odd the numbers int esum [] = new int [25]; //sum of all even numbers int sum = 0; while (Scan.hasNext()){ //Starts the while loop // Read the next number. int numList = Scan.nextInt(); if (numList %2==0 ) { // TODO } // Display the last number read. //System.out.println(numList); sum = sum + numList; numbersCounter++; } System.out.println("Average: " + (sum/numbersCounter)); } }
int oddSum = 0;int oddCount = 0;int evenSum = 0;int evenCount = 0;// loop Read next number If ODD Add number to oddSum Add 1 to oddCount Else do the same for evensAt end of loop, calculate the averages and print them.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)