java求π的问题? public class Pi { public static void main (String [] args ){ int i = 1; double sum
为什么输出的sum都是1.0000publicclassPi{publicstaticvoidmain(String[]args){inti=1;doublesum=0....
为什么输出的sum都是1.0000
public class Pi {
public static void main (String [] args ){
int i = 1;
double sum = 0.0;
int flag = 1;
for (i=1;i<1000;i++){
sum = sum + flag*1/(2*i-1);
System.out.printf("%.5f ",sum);
flag = - flag;
}
System.out.printf("%.5f",sum);
}
} 展开
public class Pi {
public static void main (String [] args ){
int i = 1;
double sum = 0.0;
int flag = 1;
for (i=1;i<1000;i++){
sum = sum + flag*1/(2*i-1);
System.out.printf("%.5f ",sum);
flag = - flag;
}
System.out.printf("%.5f",sum);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询