Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

finding the lowest of 4 values

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
jtiernan2008
Asked:
jtiernan2008
2 Solutions
 
objectsCommented:
You can use Math.min()

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

or use if

int min = Integer.MAX_VALUE;
if (A
0
 
jtiernan2008Author Commented:
so this would be

min=Math.min(A,B,C,D);
0
 
VenabiliCommented:
No, you can have only two parameters so as objects showed above, you need to nest them
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
objectsCommented:
min only takes two params so you need to call it muliple times

0
 
aman123_123Commented:
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
 
jtiernan2008Author Commented:
thanks a million
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now