• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Finding the Median

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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???
 
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic