Sort numbers in Java to find minimum and maximum values without using Array

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.

• Genius! I didn’t know of those methods in java, Math.min() and Math.max(); Very useful thanks for sharing.

• I did a course of Java and for this method i’ve learned another algorithm. This method works too.

• Corazon

Nice article ! But I don’t think I can cope with it . LOL ! My nose is bleeding when it comes to math .

• RAGHAV

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 ! ðŸ™‚

• thanks i will use this script codes

• Funmi F

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));

• Tomi R

reali nyc…. fnx guys

• sat

thanks for the method! i really learned from u! God bless ðŸ™‚

• 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.

• What you said made a ton of sense. But, think on this, what if you were to
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.

what you’ve written. In my opinion, it might bring your blog a little bit more interesting.

• 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 =)

• 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/

• 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.

• 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

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!

• Good day! This is my first comment here so I just wanted
to give a quick shout out and tell you I genuinely
that cover the same subjects? Thanks a lot!

• I visited several web sites but the audio feature for audio songs current at this site is really wonderful.

• 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..

• Thanks for finally writing about > Sort numbers in Java to find minimum and maximum values without using
Array < Loved it!

• I like it when individuals come together and share
views. Great website, keep it up!

• ?????? ?????? ? ???? ??????? ??? ???? ???
??? ????? ???? ???? ???? ???? ?? ????? ???????? ? ?? ???????????????
?? ???? ? ??? ???1
? ? ?????? ???? ??? ?? ?? ? ???????

• 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/

• Why people still make use of to read news papers when in this technological globe all is
existing on net?

• 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

• 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

• 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

• What’s up, I wish for to subscribe for this website to obtain latest updates, thus where can i do it please help.

• ????????????????????????yr-?????????????????????ft???????????????????????? ???? ?????????????????????????? ???? ?????? ????
???????????? ??? ?? .

• Hello There. I found your blog using msn.

This is a very well written article. I will be sure
Thanks for the post. I’ll certainly return.

Feel free to surf to my web site … no przecie? nie

• 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.

• If some one wants expert view on the topic of running a blog after that i recommend
him/her to go to see this website, Keep up the nice job.

• Hi colleagues, how is everything, and what you want to say
concerning this article, in my view its actually awesome designed for me.

• Asking questions are really pleasant thing if you are not understanding something entirely, but this paragraph gives nice understanding yet.

• With havin so much written content do you ever run
into any issues of plagorism or copyright violation?
My website has a lot of unique content I’ve either authored myself or outsourced but it looks like a lot of it is popping it up all over the web without my authorization. Do you know any techniques to help prevent content from being stolen? I’d truly appreciate
it.

• Johna297

It is actually a nice and helpful piece of information. I am happy that you simply shared this helpful information with us. Please stay us informed like this. Thank you for sharing. fcfbffgfeged

• Wonderful goods from you, man. I’ve understand your stuff previous to
and you’re just extremely great. I really like what you have acquired here, certainly like what you are saying and the
way in which you say it. You make it enjoyable and you still care for to keep
it sensible. I can’t wait to read far more from you.
This is actually a wonderful website.

• Greetings from Colorado! I’m bored at work so I decided to
check out your website on my ipgone during lunch break.
I love the info you present here and can’t wait to take a look
when I get home. I’m amazed at how fast your blog loaded
on my phone .. I’m not even using WIFI, just 3G ..
Anyways, superb blog!