What does the ^ operator do in Java?

前端 未结 17 1976
执念已碎
执念已碎 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:49

    As others have said, it's bitwise XOR. If you want to raise a number to a given power, use Math.pow(a , b), where a is a number and b is the power.

提交回复
热议问题