编写java程序,实现使用while循环条件语句计算1+1/2!+1/3!+1/4…+1/99!之和

日期:2016-04-29 09:43:08 人气:2

编写java程序,实现使用while循环条件语句计算1+1/2!+1/3!+1/4…+1/99!之和

先写个求阶乘的方法: public static int jieCheng(int n) { int result = 1; for (int i = 1; i <= n; i++) { result *= i; } return result; } 然后如你要求的用dowhile()循环计算:(也给你写了个方法) public static double caculate(int n) { double sum = 0.0; int i=1; do{ sum = sum +
    A+
热门评论