# Thread: Median and mode HELP!

1. Member
Join Date
Oct 2012
Posts
3
Rep Power
0

## 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
Last edited by Gamedisolver; 10-09-2012 at 06:06 AM.

2. ## Re: Median and mode HELP!

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.

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.

3. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,565
Rep Power
12

## 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.

#### Posting Permissions

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