How to correctly print the following expression? Math.Pow (2, (1/12));

Asked

Viewed 21 times

0

The expression 2^(1/12) should present the result: 1,0594630943593. But when I apply the Math.Pow function the result only gives 1.0. Could someone help me and tell me how to print the correct amount?

I’m using the following code:

double x = Math.pow(2, (1/12));
System.out.println(x);
SAÍDA: 1.0
  • 1/12 is a division of integers and the result is an integer. Try 1.0/12.

  • It’s true. I didn’t notice this fact. Thank you very much!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.