I need to find the median of 5 integers for a program. Currently i am sorting the numbers using Math.min and Math.max. If someone has a slightly more elegant way please post here.

Printable View

- 05-31-2007, 05:08 PMHasanFinding Median of X Integers
I need to find the median of 5 integers for a program. Currently i am sorting the numbers using Math.min and Math.max. If someone has a slightly more elegant way please post here.

- 05-31-2007, 05:12 PMValeriano
You should use an array and take a look at Arrays.sort(). This is one way of doing it, if-else and ternary are no good. If this is an assignment then you should look to deliver code that will work for any number of values even if your assignment works only with five numbers, the same algorithm should work with any amount.

Arrays (Java 2 Platform SE 5.0) - 08-12-2008, 02:48 PMg25451
how are you?

- 08-12-2008, 03:06 PMFubarable
Abuse reported on g25451 for spamming the forums.