Hey. I need some help with this one:
"Write a program that gets n numbers from a user. The program then displays two averages. One average is that of all the even numbers that were entered, and the second is for the odds."
RULES:
-No more than one loop
-No more than one if-else statement.
-Output must say The average of inputed values is... (Example: The average of 23, 21, 19, and 25 is 22.)
I am having trouble. I can get it where it does the average of all numbers, but I can't get it to where it does the evens and odds and outputs them like (The average of 23, 21, 19, and 25 is 22). Can somebody please help.
Here is the code I have so far:
import java.util.Scanner;
class EvenOddAlex {
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
double avg;
double sum = 0;
int num;
int count = 0;
System.out.println("How many numbers? ");
int n = scan.nextInt();
for(int i = 1; i <= n; i++)
{
System.out.println("Enter a number");
num = scan.nextInt();
{
count = count + 1;
sum = sum + num;
}
}
avg = sum/n;
System.out.println("The average of " + n + " is " + avg);
}
}