wood burning stoves*
The moose likes Java in General and the fly likes Finding the Median Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Finding the Median" Watch "Finding the Median" New topic
Author

Finding the Median

Marcus Soukup
Greenhorn

Joined: May 05, 2004
Posts: 2
For my program I need to have people inputing 10 numbers and then finding the median of these numbers.
The way I would find out this median is:
1: Arrange the numbers in order by size
2: Find the two middle terms and then the mean of them.
4: Print out answer
I need help with the array and how to sort it and then how the hell to find the two middle numbers.
Thanks!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10925
    
  12

If you have to use an array, then you're going to have to write your own sort. If you KNOW that there will ONLY be 10 numbers, an insertion sort woulnd't be too hard, and fairly quick.
as to finding the two middle numbers...once the array is sorted, you would just want to get element 4 and 5. None of this sounds too hard. When is it due???


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
William Zimmerman
Greenhorn

Joined: Apr 30, 2004
Posts: 8
Try:
http://java.sun.com/applets/jdk/1.4/demo/applets/SortDemo/example1.html
or
http://www.jadcentral.com/codecentral/code_profile.jsp?category_ID=4&code_ID=118
Tim West
Ranch Hand

Joined: Mar 15, 2004
Posts: 539
If you use an array, you can use Arrays.sort(myArray).
That said, if this is an assignment you'll probably not be allowed to use such library methods.
Cheers,

--Tim
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding the Median
 
Similar Threads
What am I missing?
linked list
Clarification for quicksort
right shifting?
CIA's World Factbook - Purchasing Power Parity (ppp) Top 5