分数求和

import java.util.Scanner;
public class Sum {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.println("i      m(i)");
        double n = input.nextDouble();
        sum(n);
    }
    public static double sum(double i) {
        double j = 0,sum = 0,k;
        for(k = i;k >= 1;k--){
            sum = k / (k + 1) + sum;
        }
        System.out.println(i + "      " + sum);
        return sum;
    }

}

计算m(i)=1/2+2/3+3/4+…...n/(n+1)

posted @ 2014-08-11 15:50  Amoxicil  阅读(156)  评论(0编辑  收藏  举报