Solved

finding the lowest of 4 values

Posted on 2009-04-06
7
174 Views
Last Modified: 2012-05-06
If I have values A, B, C and D
and I wish to find which has the lowest value.

What would be the best way to do this?
0
Comment
Question by:jtiernan2008
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
Comment Utility
You can use Math.min()

min = Math.min(A, Math.min(B, ....

or use if

int min = Integer.MAX_VALUE;
if (A
0
 
LVL 1

Author Comment

by:jtiernan2008
Comment Utility
so this would be

min=Math.min(A,B,C,D);
0
 
LVL 20

Expert Comment

by:Venabili
Comment Utility
No, you can have only two parameters so as objects showed above, you need to nest them
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 92

Expert Comment

by:objects
Comment Utility
min only takes two params so you need to call it muliple times

0
 
LVL 4

Assisted Solution

by:aman123_123
aman123_123 earned 200 total points
Comment Utility
Here are two ways to achieve the same.

Using list and sort it:
List<Integer> list = new ArrayList<Integer>();
        list.add(100);
        list.add(10);
        list.add(15);
        Collections.sort(list);
        for(int a:list)
            System.out.println(a);
       

Using Sorted set i.e tree set
        Set<Integer> set = new TreeSet<Integer>();
        set.add(100);
        set.add(10);
        set.add(15);
       
        for(int a:set)
            System.out.println(a);


First element of these collections will always be the minimum.
0
 
LVL 1

Author Closing Comment

by:jtiernan2008
Comment Utility
thanks a million
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countX 22 69
maven java path setting 5 49
Saving Tweets with emojis using Twitter4J in a Mysql table 2 50
Java DateChooser? 2 0
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now