1. Member
Join Date
Mar 2010
Posts
2
Rep Power
0

Hey guys, im new here and need some help as i see that many of you here are good at java.

Heres the prompt:

Write a program that takes 10 numbers as inputs. The program then displays the average of the numbers followed by all of the numbers that are greater than the average. As part of your design, write a method that takes an array of doubles as a parameter and returns the average of the data in the array

I have tried to do as much as i can and ill link it below but i am no good at using methods, let alone passing values to and from it. So all they help is really appreciated. Could you also let me know if im not following the prompt correctly or mis-read it.

Thanks

Heres what i have so far:

import java.util.Arrays;
import java.util.Scanner;

public class AverageNumbers {

public static void main (String[]args){

Scanner reader = new Scanner (System.in);

int size = 5;
double sum = 0, average;
double [] numArray = new double [size];

for(int i = 0; i < numArray.length; i++){
}

for(int i = 0; i < numArray.length; i++){
sum += numArray[i];
}

average = sum / size;

System.out .println("Average: " + average);

for(int i = 0; i < numArray.length; i++){
if(numArray[i]>average){
System.out.println("These numbers are greater than the average: " + numArray[i]);
}

}

}
}

2. Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

Use code tags when posting code, that is &#91;CODE]your code goes here&#91;/CODE]

3. Originally Posted by light-flyer
Write a program that takes 10 numbers as inputs.
Java Code:
```		int size = 5;
double [] numArray = new double [size];```
I guess your assignment meant 10 as in 10 decimal, not as in 10 base 5. ;-)

kind regards,

Jos

4. Member
Join Date
Mar 2010
Posts
2
Rep Power
0
oh sorry about that PhHein, will do thanks.

JosAh , i did mean 10 but as im testing it im saving the trouble and time by just entering 5 integers at first.

5. Originally Posted by light-flyer
JosAh , i did mean 10 but as im testing it im saving the trouble and time by just entering 5 integers at first.
I was only joking, but seriously now: what actually are your problems? Creating methods? Here is one method skeleton: it is supposed to read the numbers for your array; you already have that code, you only should move it into the following method:

Java Code:
```public static void readNumbers(double[] array) {

// read numbers into the array

}```

In your main( ... ) method you should call this method if you want numbers read into your array:

Java Code:
```// somewhere in the body of your main( ... ) method
kind regards,

Jos

Posting Permissions

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