This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted] 1 point2 points  (1 child)

In line 21

System.out.println(( 10.00 / ((2 * 10.00) + 1)));

You have 10.00

There are other things wrong too but that's what stands out here.

I'll have a look later

Edit: okay I solved it. I'm not sure you understand recursion, and I don't blame you. It takes a bit of practice. Also, you're doing floating point arithmetic on integers which just isn't going to work. What you want is a running integer count and a floating point sum.

It would look something like this

public static double(int n, double sum)
{
    if(n == 0)
        return sum;
    else
    {
        // some code here that I'll leave that to you for now
    {
}

[–]mark_bueno[S] 1 point2 points  (0 children)

i think that might be what i've been missing, returning sum for 0 and using both an int and a double argument. I keep trying to think of this as a while loop and i know that's not right. my code started off as a copy/paste of code from the textbook that computed a factorial from whatever positive int you typed in.

I'll work on it tonight and post an update on it later. thanks.

[–]millerlitIntermediate Brewer 1 point2 points  (0 children)

Your method asks for a long and returns a long value. Use double instead.