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, 04: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, 04: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, 01:48 PMg25451
how are you?

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