0

Possible Duplicate:
Creating a “logical exclusive or” operator in Java

I'm struggling with trying to write Java code for an exclusive or operator.

I have 1 method called leftTurn()

leftTurn(a,b,c) XOR leftTurn(a,b,d) 

&

leftTurn(c,d,a) XOR leftTurn(c,d,b) 

I dont know how to construct Java code for this.

2
  • 1
    See stackoverflow.com/questions/726652/… Commented Dec 5, 2011 at 11:16
  • Can't you use the regular '^' XOR operator? Commented Dec 5, 2011 at 11:16

3 Answers 3

5

The Java XOR operator is ^.

So:

leftTurn(a,b,c) ^ leftTurn(a,b,d) 
Sign up to request clarification or add additional context in comments.

Comments

2

Assuming leftTurn return int

leftTurn(a,b,c) ^ leftTurn(a,b,d) leftTurn(c,d,a) ^ leftTurn(c,d,b) 

Comments

2

If ^ is a bit obscure for you, you can just use != which does the same thing for booleans.

boolean oneTurn = leftTurn(a,b,c) != leftTurn(a,b,d); 

If you need bitwise XOR, you need ^

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.