For instance, would this program run:
*loop code.......*
if (variable1 != variable2 != variable3 != variable4){break loop;}
For instance, would this program run:
*loop code.......*
if (variable1 != variable2 != variable3 != variable4){break loop;}
What you're really trying to test is whether there are any duplicate values in your set of variables. Here's a simple method to test that:
static boolean allUnique(Object... values) {
return new HashSet<>(Arrays.asList(values)).size() == values.length;
}
You can call it like this:
if (allUnique(variable1, variable2, variable3, variable4)) break loop;
Yes, you need to use the logical &&
AND operator.
More info in this SO answer.
Essentially you will use something like:
if (variable1 != variable2 && variable1 != variable3 && variable1 != variable4)
This will check that variable 1 is not equal to 2, 3 or 4.