英语翻译这是一个java编程题,题目是英文的,想要翻译,如果能完成程序编写,追加100分Pi can be calculated using the following sum,which is an approximation to Pi/4 :PiSum = 1 - 1/3 + 1/5 - 1/7 + ...+ (-1)^n / (2*n + 1)1) Writ

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/26 09:59:08
英语翻译这是一个java编程题,题目是英文的,想要翻译,如果能完成程序编写,追加100分Picanbecalculatedusingthefollowingsum,whichisanapproxima

英语翻译这是一个java编程题,题目是英文的,想要翻译,如果能完成程序编写,追加100分Pi can be calculated using the following sum,which is an approximation to Pi/4 :PiSum = 1 - 1/3 + 1/5 - 1/7 + ...+ (-1)^n / (2*n + 1)1) Writ
英语翻译
这是一个java编程题,题目是英文的,想要翻译,如果能完成程序编写,追加100分
Pi can be calculated using the following sum,which is an approximation to Pi/4 :
PiSum = 1 - 1/3 + 1/5 - 1/7 + ...+ (-1)^n / (2*n + 1)
1) Write two methods that return PiSum for a specified value of n,one method
using recursion and the other using iteration to do the sum.
Hint:instead of calculating (-1)^n,you can check whether the nth term is
negative by checking whether n%2 (i.e.n modulo 2) is 1.
Assume that the methods are always called with a non-negative value of n,so you
don't need to worry about dealing with invalid parameter values.
2) Show the additional code you would add to the above methods to throw an
exception if n is less than zero (you don't need to rewrite the whole method).The
exception handler should generate an error message saying that the number of terms
in the sum must not be negative.
Write a code fragment (i.e.it doesn't need to be a complete method) that invokes
one of the methods for calculating Pi and prints out the result if the method returns
correctly,or else catches an exception and prints out the error message returned.
3) When calculating Pi using the given formula,suppose that instead of passing a
parameter specifying the number of terms n in the sum,we instead want to pass a
parameter that specifies a precision value.The sum should terminate at the first value
n for which the absolute value of the nth term in the sum,i.e.1/(2*n+1) is less than
the specified precision.Show how this can be implemented using a do loop.

英语翻译这是一个java编程题,题目是英文的,想要翻译,如果能完成程序编写,追加100分Pi can be calculated using the following sum,which is an approximation to Pi/4 :PiSum = 1 - 1/3 + 1/5 - 1/7 + ...+ (-1)^n / (2*n + 1)1) Writ
我有一个类似的代码.将就着用把
大概意思是一样的只是没有异常处理
public class a2and5
{
public static void main(String [] agrs)
{
int count=0;
double pi=0.0,l=1.0,diff,pi1;
diff=1;
while(Math.abs(diff)>0.01)
{
pi1=pi;
pi+=((4.0/(count*2.0+1.0))*l);
l*=-1.0;
System.out.print(pi+" "+count+"\n");
count++;
diff=pi1-pi;
}
}
}
/*
3.1467739659661436 192
3.136438048653482 193
3.1467208250030967 194
3.1364906459749635 195
3.1466687630233094 196
3.1365421807448284 197
3.146617747495458 198
3.136592684838816 199
3.1465677471829556 200 */

英语翻译这是一个java编程题,题目是英文的,想要翻译,如果能完成程序编写,追加100分Pi can be calculated using the following sum,which is an approximation to Pi/4 :PiSum = 1 - 1/3 + 1/5 - 1/7 + ...+ (-1)^n / (2*n + 1)1) Writ JAVA编程,输入一个四位数,求四位数的每位数字之和!是JAVA,不是C语言! java程序问题?下面是一个 5*5 的螺旋方阵(顺时针方向旋转)编程输出 10*10(n SCALE_DEFAULT是什么意思是用java编程时,看到的一个常量,我刚学,看不明白啊,谢谢啦 java编程:趣味填空有这样一个趣味填空题:给出用等号连接的两个整数,如“1234=127”.当然,现在这个等号是不成立的.题目让你在左边的整数中间某个位置插入一个加号,看有没有可能让等号 英语翻译翻译一个编程code blocks是要下载吗? 求Java编程,计算并输出1+2!+3!+…+10!的值提问错了,是图片的那个题目 JAVA题目 :随机生成100个1000以内的整数,将这100个整数中的素数找出来并写到一个文本文件中.急 用最简单的JAVA程序来编程 ,容易看的懂的 用java语言编程 设y=f(x)是一个分段函数,表达式如下用java语言编程 设y=f(x)是一个分段函数,表达式如下:请编写一个Java程序,实现以下功能:定义任意一个实数x,即可计算并输出对应的 y输入 用JAVA编程从键盘输入一个正整数,计算该数的各位数字之和并输出,例如输入数是5246 让大家一个java非常简单的编程:根据输入1到12之间的数字,判断是春夏秋冬哪个季节要求使用方法定义四个季节 什么叫反射机制我说的是java编程中的反射机制啊- - java里 编程计算1至50中是7的倍数的数值之和 英语翻译这是编程语言测试的句子 一道java编程题,10个评委打分,去带最高分和最低分,剩下的8个的平均分是选手最终成绩10个评委对某选手评分,去掉一个最高分,去掉一个最低分,剩余8个评委的平均分作选手的最终成绩用java编 java 实例域 是一个范围吗 JAVA输入三角形的三条边,判断是否是一个三角形,三角形的形状JAVA语言实现一下这个题目:输入三角形的三条边判断是否等边三角形,等腰三角形,不等边三角形; 简单小题,大家帮忙这是java最基础的一道编程题,是构造一个数组,然后输出最大值,下面的代码也是正确的,但貌似不是很符合编码规范,大家帮忙转化下,谢谢啦public class max { public static void ma