Saturday, 10 August 2013

Sort an amount of user entered numbers according to size (Java)

Sort an amount of user entered numbers according to size (Java)

I'm trying to figure out how to sort a user defined number of user defined
numbers according to size, the user defined numbers are doubles.
I'm trying to do it without using arrays or anything too complex, ideally
using some form or combination of Math.min and Math.max
eg
int lowestNumber = (int)Math.min(firstNumber, (Math.min(secondNumber,
Math.min(thirdNumber, finalNumber))));
This gets me the lowest number, that's fine, but when i try and do
int secondLowestNumber = (int)Math.min(lowestNumber, firstNumber,
(Math.min(secondNumber, Math.min(thirdNumber, finalNumber))));
I get the lowest number again. I guess the problem is that I don't know
how to eliminate the lowest number once I've completed the first
assignment.
If anybody has any tips, I would love to hear them!
Thanks

No comments:

Post a Comment