• 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

To find the Medium

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can anyone find the medium of a given input? Using this code I have tried but I failed
But I think there�s a easy way of doing that,
Medium means
Input : 2 4 5 6 6 6 7 7 8
Considering on above number sequence the medium is 6
Please someone can figure this out leave a comment



[BPSouther: Added code tags]
[ March 10, 2008: Message edited by: Ben Souther ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you say it failed, what do you mean exactly?
What results were you expecting?
What results did you see?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it's the "median" you're after.

Before trying to code this, can you describe the steps you need to take (considering that the input might not always be ordered)?

Also, your calculation for "average" (mean) will only work if you have 2 elements (or if all your elements are zero). Do you see why?
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The formula you are using to find out average is incorrect. It is not always 'sum/2'. The correct formula is 'sum/number of terms' instead.

Hope this helps!
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
To find the median of the series,the following code can be used.



Hope this helps you.
-Thanks & Regards,
Hamsa
 
Hamsagayathri Palanisamy
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
To find the median of the series,the following code can be used.



Hope this helps you.
-Thanks & Regards,
Hamsa
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


If number of integers entered is an even number, then there will be two medians.
If no. of integers entered is an odd number, then only one median we will have...

[ March 18, 2008: Message edited by: agilemanoj kumar ]
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and this applies to the SCJP how?
 
Hamsagayathri Palanisamy
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by agilemanoj kumar:

If number of integers entered is an even number, then there will be two medians.
If no. of integers entered is an odd number, then only one median we will have...


[ March 18, 2008: Message edited by: agilemanoj kumar ]





Hi agilemanoj,
if the number of integers entered is even number,i think there is no two medians, For example:
Integers entered are:
1 2 3 4 5 6
Then Median is: (3+4) /2 = 3.5
and if the integers entered are: 1 2 3 4 5
Median is: 3
I hope above one is median calculation and please correct me if i'm wrong.

-Thanks & Regards,
Hamsa
 
reply
    Bookmark Topic Watch Topic
  • New Topic