public class test3 {
public static void main(String[] args) {
double PI=0,n,pi=0;
Scanner sc=new Scanner(System.in);
System.out.println("请输入n的值");
n=sc.nextDouble();
for(double m=1;m<=n;m++) {
if(m%2==1)pi+=1/(2*m-1); //决定前面的正负号
else pi-=1/(2*m-1);
}
PI=4*pi;
System.out.println("当n为"+n+"时π的值为"+PI);
}
}