wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes sorting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "sorting" Watch "sorting" New topic
Author

sorting

terry oliver
Greenhorn

Joined: Jan 04, 2008
Posts: 22
what is the best way to sort three double variables in ascending order

thanks Olly
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

Depends what your definition of best is. Also, you must consider what to do when any of the doubles is NaN - that will not compare to anything.

Fast method:

There is a more generic method however, for any number of (non-NaN) numbers:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3219
SCJP 1.4 100%


Good stuff.


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19679
    
  18

Thank you. I think I got lucky on a few questions though.
 
Don't get me started about those stupid light bulbs.
 
subject: sorting