Demo entry 6643779

计算1-1/3+1/5-1/7+1/9-1/11+…的前1000项之和

   

Submitted by anonymous on Sep 29, 2017 at 04:48
Language: Java. Code size: 325 Bytes.

//编写一个Java应用程序,计算1-1/3+1/5-1/7+1/9-1/11+…的前1000项之和
public class D03
    {
        public static void main(String args[])
        {
            double sum=0,sign=1;
            for(int i=0;i++<10000;sign*=-1)sum+=sign*1/(2*i+1);
            System.out.printf("1-1/3+1/5-1/7+……的前10000项和为:%.20f",sum);
        }
    }

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).