Do you want XNOR, basically:
if (!(a ^ b))
or (easier)
if (a == b)
where a and b are conditions.
Code example:
public class Test { public static void main(String[] args) { xnor(false, false); xnor(false, true); xnor(true, false); xnor(true, true); } private static void xnor(boolean a, boolean b) { System.out.printf("xnor(%b, %b) = %b\n", a, b, a == b); } }
Produces this truth table;
xnor(false, false) = true xnor(false, true) = false xnor(true, false) = false xnor(true, true) = true
Jon skeet
source share