# Help with an arrays assignment

• 02-20-2007, 08:42 AM
MindGAckt
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;

for(int i=0; i<list.length; i++)
{
System.out.print("Enter a number: ");
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];

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

}
}
• 02-20-2007, 09:54 AM
anubis
once you find your average, so can do something like this

Code:

```for(int i = 0; i < list.length; i++) { if(list[i] > avg) System.out.println(list[i]); }```
• 02-20-2007, 06:52 PM
MindGAckt
So do i put that under
float avg = sum/list.length;

?
• 02-21-2007, 09:01 AM
Kinda Electroni
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
• 02-21-2007, 11:05 AM
MindGAckt
Ya i got it now, thx for the help :tup: