非常非常卡java精度 直接%.6f是不可能过的 一直答案错误91% 对java非常不友好
一定要格式化000000
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static double fun(int n, int m, double s) {
if (m > n) {
return s;
} else {
return fun(n, m + 1, s + 1.0 / (m * (m + 1)));
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
DecimalFormat a = new DecimalFormat("0.000000");
System.out.println(a.format(fun(n,2,0.5)));
}
}