# Median and mode HELP!

• 10-09-2012, 04:52 AM
Gamedisolver
Median and mode HELP!
Ok so my math final is due tomorrow and part of it is i have to get a user input for 10 numbers and find the median and mode. I need Them to be in separate classes. I need The median needs to be able to have two answers and find the average of them them. Mode has to be able to have 2 answer example: 2344214978.

p.s. I already spent 5 hours on trying to make it work but it won't.

I dont have much code at all.

import java.util.Arrays;

public class median {
public static void main(String[] a){
int[] numbers = {9, 4, 6, 2, 1, 8, 7};
printNumbersInOrder(numbers);
}
public static void printNumbersInOrder(int[] numbers){
Arrays.sort(numbers);
for(int i = 0; i < numbers.length; i++)
System.out.println(numbers[i]);
}
}
this code just orders it

i have nothing for median anymore I was trying to use a bunch if if statments but that really failed
• 10-09-2012, 04:56 AM
Fubarable
Re: Median and mode HELP!
Quote:

Originally Posted by Gamedisolver
Ok so my math final is due tomorrow and part of it is i have to get a user input for 10 numbers and find the median and mode. I need Them to be in separate classes. I need The median needs to be able to have two answers and find the average of them them. Mode has to be able to have 2 answer example: 2344214978.

I think I speak for all in saying that you have our full permission to do this, and we wish you godspeed on your success.

Quote:

p.s. I already spent 5 hours on trying to make it work but it won't.
If you need our help, you'll need to post your code, tell us about your errors, etc. We're terrible at guessing at these things.
• 10-09-2012, 06:14 AM
pbrockway2
Re: Median and mode HELP!
Why did you sort your array?

I guess I'm really asking what your plan of attack is to find the median. It is really important to have such a plan (aka algorithm) quite precisely fixed in you mind (and be able to express it to others) before you start writing code. Otherwise you run the risk of thrashing about fighting the compiler errors but not really knowing whether you're making progress.