Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Help with an arrays assignment

The assignment is basically having to take 10 floating point numbers as inputs in an array and then finding the average. The program should then return the average followed by all of the numbers greater than the average.

I already figured out how to find the average and displaying it but i cant figure out how to display the numbers greater than the average.

This is what i have so far if it helps any

import java.util.Scanner;
public class ArraysAverage
{
public static void main(String[] args)
{
int[] list=new int[10];
int num = 0, bignum=0;
float sum = 0;

Scanner reader = new Scanner(System.in);

for(int i=0; i<list.length; i++)
{
System.out.print("Enter a number: ");
list[i] = reader.nextInt();
sum += list[i];

}
float avg = sum/list.length;
System.out.println("The average is: " + avg );


}
public static double Total(int[] list){
double Total = 0;
for(int i=0; i<list.length; i++)
{
Total += list[i];

}
return Total;
}
public static double average(int[] list, double Total){
double average = (Total/(list.length));
return average;

}
}
[1313 byte] By [MindGAckt] at [2007-11-11 10:26:00]
# 1 Re: Help with an arrays assignment
once you find your average, so can do something like this

for(int i = 0; i < list.length; i++)
{
if(list[i] > avg)
System.out.println(list[i]);
}
anubis at 2007-11-11 22:31:32 >
# 2 Re: Help with an arrays assignment
So do i put that under
float avg = sum/list.length;

?
MindGAckt at 2007-11-11 22:32:32 >
# 3 Re: Help with an arrays assignment
float avg = sum/list.length;
System.out.println("The average is: " + avg );
It would be better if you insert it here.
Further more to make it more fancy you can use this
System.out.println(" i = " + i + list[i]);
I would like to learn try both, one at a time and see the difference.
Good luck
Kinda Electroni at 2007-11-11 22:33:31 >
# 4 Re: Help with an arrays assignment
Ya i got it now, thx for the help :tup:
MindGAckt at 2007-11-11 22:34:30 >