Help with an arrays assignment

 DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Help with an arrays assignment

1. Registered User
Join Date
Oct 2006
Posts
11

## 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: ");
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;

}
}

2. Registered User
Join Date
Dec 2005
Posts
97
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]);
}```

3. Registered User
Join Date
Oct 2006
Posts
11
So do i put that under
float avg = sum/list.length;

?

4. Registered User
Join Date
May 2005
Location
Posts
173
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

5. Registered User
Join Date
Oct 2006
Posts
11
Ya i got it now, thx for the help :tup:

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise
 Questions? Contact us. C++ Web Development Wireless Latest Tips Open Source