Sort numbers in Java to find minimum and maximum values without using Array
May 21
Recently a reader contacted me with a question about sorting numbers in Java. After sorting the number the program then needs to print the largest and smallest values. I have written a post earlier that shows one way of finding largest and smallest numbers. That approach used Arrays but the reader wanted to find largest and smallest values from a group of numbers without using Arrays. So here is another approach.
This program accepts input from the user and then prints out the largest and smallest numbers.
import java.util.*;
public class NumberSorter{
public static void main(String args[]){
double a, b, c, x, y;
Scanner console = new Scanner(System.in);
System.out.print("Enter the first number: " );
a = console.nextDouble() ;
System.out.print("Enter the second number: " );
b = console.nextDouble() ;
System.out.print("Enter the third number: " );
c = console.nextDouble();
x= Math.min(a, Math.min(b, c));
y= Math.max(a, Math.max(b, c));
System.out.println("\n" +x + " is the smallest number.\n" + y
+" is the largest number.");
}
}
Hope you find this useful. Share your ideas on how else can we find largest and smallest values from a group of numbers Java.
If you enjoyed this post, make sure you subscribe to my RSS feed!






Sep 10, 2010 @ 20:08:58
Genius! I didn’t know of those methods in java, Math.min() and Math.max(); Very useful thanks for sharing.
Dec 07, 2010 @ 00:32:57
this is great! i havnt thought about this procedure.
Oct 05, 2011 @ 13:37:28
I did a course of Java and for this method i’ve learned another algorithm. This method works too.
Oct 06, 2011 @ 06:48:27
Nice article ! But I don’t think I can cope with it . LOL ! My nose is bleeding when it comes to math .
Oct 12, 2011 @ 12:50:25
we can even divide the numbers in two – two parts n use if statements to compare the larger n smaller value .. that is a much easier way to understand .. according to me !
Oct 14, 2011 @ 01:44:27
thanks i will use this script codes
Oct 27, 2011 @ 23:34:15
The following can also work:
Double[] dblArr = {a, b, c, x, y};
double x=Collections.min(Arrays.asList(dblArr));
double y = Collections.max(Arrays.asList(dblArr));
May 24, 2012 @ 03:59:34
reali nyc…. fnx guys
May 25, 2012 @ 08:43:24
thanks for the method! i really learned from u! God bless
Dec 24, 2012 @ 16:42:57
Hi there to every body, it’s my first pay a quick visit of this webpage; this website carries awesome and genuinely excellent information in support of visitors.
Jan 01, 2013 @ 00:03:49
What you said made a ton of sense. But, think on this, what if you were to
write a killer headline? I am not suggesting your information is
not good, but suppose you added a title to maybe grab people’s attention? I mean Sort numbers in Java to find minimum and maximum values without using Array is a little plain. You might look at Yahoo’s home page
and watch how they create post titles to grab people to open the links.
You might try adding a video or a pic or two to grab readers interested about
what you’ve written. In my opinion, it might bring your blog a little bit more interesting.
Jan 06, 2013 @ 12:16:09
Terrific article! This is the type of information that should be shared across
the net. Shame on Google for no longer positioning this post upper!
Come on over and talk over with my website . Thank you =)
Feb 18, 2013 @ 04:22:17
You can even reuse these and have whatsoever you like. The firm was started by British designers Melanie Marshall and Suzi Bergman.
A single has to verify for certificate expiry, and authorities who have licensed this website.
The initially matter you have to assume about is
the measurement. http://www.miumiubagsjps.
com/
Mar 10, 2013 @ 18:15:30
It’s genuinely very complex in this full of activity life to listen news on Television, therefore I just use web for that reason, and get the newest news.
Mar 13, 2013 @ 13:52:47
Do you have a spam problem on this website; I also am a blogger, and I was curious about your situation; many of us have created some
nice practices and we are looking to swap techniques with other folks, why not shoot me
an email if interested.
Also visit my homepage; How To Make A Blog
Mar 14, 2013 @ 06:49:19
Have you ever thought about adding a little bit more than just your articles?
I mean, what you say is important and everything. But imagine if you added
some great images or video clips to give your posts
more, “pop”! Your content is excellent but with pics and video clips, this
website could certainly be one of the best in its niche.
Good blog!
Mar 15, 2013 @ 11:58:11
Good day! This is my first comment here so I just wanted
to give a quick shout out and tell you I genuinely
enjoy reading your posts. Can you suggest any other blogs/websites/forums
that cover the same subjects? Thanks a lot!
Mar 15, 2013 @ 17:50:12
I visited several web sites but the audio feature for audio songs current at this site is really wonderful.
Mar 21, 2013 @ 09:23:58
I’m really impressed with your writing skills as well as with the structure in your weblog. Is this a paid theme or did you modify it yourself? Either way keep up the excellent quality writing, it is uncommon to see a nice blog like this one these days..
Mar 22, 2013 @ 12:59:19
Thanks for finally writing about > Sort numbers in Java to find minimum and maximum values without using
Array < Loved it!
Mar 30, 2013 @ 02:59:16
I like it when individuals come together and share
views. Great website, keep it up!
Apr 09, 2013 @ 00:23:07
?????? ?????? ? ???? ??????? ??? ???? ???
??? ????? ???? ???? ???? ???? ?? ????? ???????? ? ?? ???????????????
?? ???? ? ??? ???1
? ? ?????? ???? ??? ?? ?? ? ???????
Apr 09, 2013 @ 22:01:43
The situation needs extremely gourmet craftsmanship. Implementing
such approaches to applying designer companies is more
low cost for an natural people. Louis Vuitton Handbags can be seen all
over the post. Need to more and more people prefer style returning to
practical use found in a bag. http://www.louisvuittongekiyasu.
com/
Apr 24, 2013 @ 00:01:52
Why people still make use of to read news papers when in this technological globe all is
existing on net?
Apr 24, 2013 @ 00:44:31
Up above all, pick a shoe that can sometimes your feet comfortable.
It holds a high-resolution multi-touch more effective inch screen by using
a wide viewing slope. A pair of good quality jogging shoes is the single most
important item a athlete can buy. Gradually, Nike shoes have become the
footwear men like to put. http://www.malamutedealaska.
com/userinfo.php?uid=26554
Apr 25, 2013 @ 12:25:39
I think that is one of the most vital information for me.
And i’m glad reading your article. However want to observation on some basic things, The site style is wonderful, the articles is in reality great : D. Good job, cheers
Apr 28, 2013 @ 07:39:39
Umbrellas and wet tissues would also offer to the over-all weight of the bags.
In stand-up humorous you need for funny,
not your entire shirt. They have a meaningful nice, snug casual fit
and also nothing is made up. Is definitely important for a high heel
shoe for you to become well fitted. http://forum.
hooptrick.org/profile.php?mode=viewprofile&u=17803
May 07, 2013 @ 00:55:33
What’s up, I wish for to subscribe for this website to obtain latest updates, thus where can i do it please help.
May 07, 2013 @ 02:08:41
????????????????????????yr-?????????????????????ft???????????????????????? ???? ?????????????????????????? ???? ?????? ????
???????????? ??? ?? .
May 11, 2013 @ 09:03:04
Hello There. I found your blog using msn.
This is a very well written article. I will be sure
to bookmark it and return to read more of your useful information.
Thanks for the post. I’ll certainly return.
Feel free to surf to my web site … no przecie? nie
May 14, 2013 @ 16:10:18
Fantastic goods from you, man. I have understand your
stuff previous to and you’re just too great. I actually like what you’ve acquired here, really
like what you’re saying and the way in which you say it. You make it enjoyable and you still care for to keep it smart. I can’t wait to read much more
from you. This is really a wonderful website.