1. 程式人生 > >計算:t=1-1/(2*2)-1/(3*3)-...-1/(m*m)

計算:t=1-1/(2*2)-1/(3*3)-...-1/(m*m)

import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
int n = scanner.nextInt();
double sum=2;
for(double i=1;i<=n;i++){   //特別注意特別注意 double與int的用法
sum-=1/(i*i);
}
System.out.println(String.format("%.6f",sum));
}
}
}