# Checking if an int is the lowest out of 4? (Small issue)

• April 30th, 2014, 07:13 PM
Rexoa
Checking if an int is the lowest out of 4? (Small issue)
I'm trying to find the int with the lowest value, and I only know how to set it up like this:

Let's say x1 is the lowest.

Code :

```int x1, x2, x3, x4;   if (x1 < x2 && x1 < x3 && x1 < x4) System.put.println("x1 is the lowest value out of those 4");```

Is there a way to shorten this at all? (It's alright if there isn't, just looking for shortcuts)
• April 30th, 2014, 07:20 PM
Norm
Re: Checking if an int is the lowest out of 4? (Small issue)
Given 4 variables, it will take some if statements to find the variable with the lowest value.
• May 1st, 2014, 04:01 AM
GregBrannon
Re: Checking if an int is the lowest out of 4? (Small issue)
I'm not sure it's worth the effort for just 4 variables, but the problem can be generalized to an efficient solution for any number of variables. That solution would include the use of an array or other collection that would be iterated to find the least value in the collection.