Java程序添加1 + 1/2 + 1/3 ..用户输入范围

时间:2017-01-23 07:11:43

标签: java recursion

public class Brain {

static int range;

double calculate() {
    double sum = 0;
    for (int n = 1; n <= Brain.range; n++) {

        sum = sum + (double) (1 / n);

    }

    return sum;

}

}

我总是得到1.0的回报。我试着在这里理解它,但没有帮助:Harmonic sequence recursion

0 个答案:

没有答案