Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Problem with nth square root of any number

1. ## Problem with nth square root of any number

OK, so now I think this is sending me crazy. I'm looking at a problem that is a mathematical problem. Now I have no problem coming up with a solution to it, that runs in under 1 second. However I want to do it using some funky Math. Anyways, after working out the Math I got one of the equations I need to compute down to

n^(1/6)

Or the 6th root of n.

Now the Java code I have for this is as follows, since Java has no nth root function I'm raising it to a power of a 1/6.
`System.out.println(Math.pow(64.0, 1/6));`
Now, the only thing it will print is 1.0
However the 6th root of 64 is 2!!!!

Chris

2. ## Re: Mathematics in Java

ARRRRRRRRRGGGGGGGHHHHHHHHHHH

I should make the 1/6 into a double... I think I may kill someone!

3. ## Re: Mathematics in Java

Ah Chris! I was just about to submit my solution!!!

`System.out.println(Math.round(Math.pow(64.0, .16)));`

4. ## Re: Mathematics in Java

Hehe thanks, but I still face one problem and that is when I wish to calculate the 6th root of 64000000, which is 20. But java makes it aprox 19.999999999999998. Unfortunately rounding is not an option

Chris

5. ## Re: Mathematics in Java

Why is rounding not an option?

6. ## Re: Mathematics in Java

because if i calculate the 6th root of 64999999 then it will be just under 19.9999999999999998, but it shouldn't be rounded up to 20, it should be rounded down to 19 xD

Chris

7. ## Re: Mathematics in Java

Could always substring it lol

8. ## Re: Mathematics in Java

How do you mean?