1

Could anyone explain to me why

System.out.println(100*(1-10^(-10/10)));

results in the number "800" being printed out? The correct answer is 90 when you use a calculator. How would I go about doing this calculation in Java?

Thanks!

Raymosrunerx
  • 179
  • 1
  • 4
  • 12

1 Answers1

9

The ^ operator does not do what you think it does. It is bitwise-xor

You need to look into the Math.pow() method.

Community
  • 1
  • 1
Kon
  • 10,702
  • 6
  • 41
  • 58
  • 1
    Please see the two links above. The xor explanation by @polygenelubricants is particularly in-depth. – Kon Jan 06 '15 at 21:31
  • 2
    In addition to this, the operation is actually more like: `100*((1-10)^(-10/10)))`, as the `-` operator has a higher precedence than the `^` operator. – Paul Richter Jan 06 '15 at 21:35