Java operator, used to check whether two conditions are false, but not both conditions are false

If any condition is false, will the operator in Java give a result of false, but if both are true or both are false, the result is true?

I have some code that relies on the user entering some values to run the process Since the user should only enter X or Y, but not both or not, I want to display an error message in this case

Solution

You want XNOR, basically:

if (!(a ^ b))

Or (more simply)

if (a == b)

Where a and B are conditions

Example code:

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);
    }
}

Make this truth table;

xnor(false,false) = true
xnor(false,true) = false
xnor(true,false) = false
xnor(true,true) = true
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>