Java如何计算1+1⼀2눀+1⼀3눀……+1⼀n눀的值(n为键盘输入的正整数)

2024-12-03 12:41:28
推荐回答(2个)
回答1:

1/(2²-1)+1/(3²-1)+1/(4²-1)+……+1/(100²-1)
=1/(1*3)+1/(2*4)+1/(3*5)+.+1/(99*101)
=1/2*(1-1/3+1/2-1/4+1/3-1/5+.+1/99-1/101)
=1/2*(1+1/2-1/100-1/101)
=1/2*14949/10100
=14949/20200

回答2:

int sum=0;

for(int i=1;i<=n;i++){
sum+=1/(i*i);

}
System.out.print(sum);