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.

Community
  • 1
  • 1
Jas Pn
  • 31
  • 2
  • 5

3 Answers3

5

The Java XOR operator is ^.

So:

leftTurn(a,b,c) ^ leftTurn(a,b,d)
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
2

Assuming leftTurn return int

leftTurn(a,b,c) ^ leftTurn(a,b,d) 
leftTurn(c,d,a) ^ leftTurn(c,d,b)
Esben Skov Pedersen
  • 4,437
  • 2
  • 32
  • 46
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 ^

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130