- import java.util.*;
- public class Test {
- public static void main(String[] args) {
- float sum = 1;
- int temp = 1;
- int n = 1;
- float flag = -1;
- System.out.print("请输入n的值:");
- Scanner sc = new Scanner(System.in);
- n = sc.nextInt();
- for(int i = 2; i <= n; i++){
- temp *= (2*i-1)*(2*i-2);
- flag *= -1;
- sum += flag/temp;
- }
- System.out.println("sum = " + sum);
- }
- }