我叫王超然,是一名电脑爱好者,现在在新加坡留学上高一.我立志成为一名电脑人才,愿意在这里与大家一同分享我玩转电脑的心得.O-level华文考了A-One哈哈!
天气: 晴朗
心情: 高兴
/*P4Q9
* Name:Wang Chaoran
* Description:(Computing p) You can approximate by using the following series
*/
public class P4Q9
{
public static void main(String[] args)
{
//Compute the pi
for(double i=10000;i<=100000;i+=10000)
{
double p = 0;
for(double j=1;j<=2*i+1;j+=2)
{
if(j%4==1)
{
p += 4 * 1/j;
}
else
{
p -= 4 * 1/j;
}
}
//Display the pi
System.out.println("If i = "+i+" p = "+ p);
}
}
}
/*P4Q9
* Name:Wang Chaoran
* Description:(Computing p) You can approximate by using the following series
*/
public class P4Q9
{
public static void main(String[] args)
{
//Compute the pi
for(double i=10000;i<=100000;i+=10000)
{
double p = 4;
for(double j=2;j<=i;j+=2)
{
p+=4*(-1/(2*j-1)+1/(2*j+1));
}
//Display the pi
System.out.println("If i = "+i+" p = "+ p);
}
}
}
导入论坛查看(73)回复(0)引用(0)好评(0) 差评(0)
加入收藏
编辑
审核
TAG:
computing