java呆谋英语怎么说_英语翻译这是一个java编程题,题目是英文的,想要翻译,如果能完成程序编写,追加100分Picanbecalculatedusingthefollowingsum,whichi...

英语翻译

这是一个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.

英语作业帮用户2017-11-15举报

6c0a0adef10d1043fa4f41a7897345ed.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值