Solved

finding the lowest of 4 values

Posted on 2009-04-06
7
176 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
ID: 24082368
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
ID: 24082433
so this would be

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

Expert Comment

by:Venabili
ID: 24082450
No, you can have only two parameters so as objects showed above, you need to nest them
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 92

Expert Comment

by:objects
ID: 24082462
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
ID: 24083879
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
ID: 31567283
thanks a million
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 104
github account with ecipse 1 47
diffSum example 4 36
couple of eclipse 5 35
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

813 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

17 Experts available now in Live!

Get 1:1 Help Now