代码:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        int n;

        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();

        double sum=0;
         for(int i=0;i<n;i++)
        {
            sum+=Math.pow(-1,i)*1/(i*3+1);
        }
         System.out.println(sum);
    }
}
0
Posted in Java

Leave a Comment:

电子邮件地址不会被公开。