近似求PI的值
package lyt;
import javax.swing.JOptionPane;
public class Lyt4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
double sum=0,s=-1;
for(long i=1;i<99999999;i++)
{
s=-s;
sum=sum+1.0/(2*i-1)*s;
}
JOptionPane.showMessageDialog(null, "PI = " + 4*sum,"ÁºÑàæÃ",JOptionPane.INFORMATION_MESSAGE);
}
}