What does the ^ operator do in Java?

前端 未结 17 1975
执念已碎
执念已碎 2020-11-22 03:27

What function does the ^ (caret) operator serve in Java?

When I try this:

int a = 5^n;

...it gives me:

17条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-22 03:42

    It's bitwise XOR, Java does not have an exponentiation operator, you would have to use Math.pow() instead.

提交回复
热议问题