Computer Science, asked by soumilinandi2006, 7 months ago

(Math.pow ( 36, 1/2 ));
Pls answer qquickl

Answers

Answered by TħeRøмαи
4

Answer:

hope it helps uhh

Explanation:

Your question is an instance of this one Division of integers in Java

Bassically, you need to cast the 1/3 part of your Math.pow() to double, because if you don't do that for default it will take the result as an Integer (always 0).

For example:

double volume = 15.34;

double fraction = (double) 1/3;

double cubeSide = Math.pow(volume,fraction);

System.out.println(cubeSide);

Output is

2.4847066359757295

Otherwise output is always 1.0. Which is the result of any number rised to the zero.

As stated in your comment, when the input is:

1000

the output should be a whole:

10

But actually its:

9.999999999999998

The simplest solution to that could be just:

float roundedValue = Math.round(cubeSide);

And say: that's not my problem. But we want to understand what that's happening. As most things in this world, you are not the first one to face this problem. Let's do some research and find that there in StackOverFlow it have been asked:

Floating point arithmetic not producing exact results

Is floating point math broken?

In the first link, its suggested to read What Every Computer Scientist Should Know About Floating-Point Arithmetic.

I wont repeat what those wise people whom know a lot more than me said, so I highly recommend to you to read the above links.

Answered by Anonymous
1

Answer:

according to python idle:

>>> import math as Math

>>> Math.pow(36,1/2)

6.0

#hope it helps you

Similar questions