我们有一个计划。现在来实现它。首先,实现一种计算圆周长的方法。要完成此任务,你需要在方法中写入正确的公式并指定参数。但是 pi 呢?我们知道它是 3.141592... 直至无穷。我们把问题简化一下:让 pi = 3.14。
计算圆的周长
- 1
已锁定
评论 (9)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
1960365339
11 三月, 02:45
我是有漏掉的课吗,怎么到这看不懂了呢
0
wen
14 十二月 2022, 03:20
public static void main(String[] args) throws Exception {
printCircleCircumference(2);
第二句"printCircleCircumference(2);"是什么意思
0
Sohyla Sherief
3 十二月 2021, 08:52
why my first requirement always has a problem?
0
null
18 三月 2021, 10:12
System.out.printf("______%2f",circle);
just like C
0
maungnge
2 十月 2020, 15:49
because double!
0
graven
8 八月 2020, 13:37
why my output is "31.400000000000002" but not "31.4" ?
very interesting
i am sure i used pi = 3.14
0
tizo chan
21 十二月 2020, 07:18
my question is same like youuu,so why??????
0
Kevin_WWW
19 二月 2021, 15:43
Computers cannot represent floating-point numbers accurately.
You can use this code:
double r = 5;
double pi = 3.14;
DecimalFormat df = new DecimalFormat("0.0");
System.out.println(df.format(2*r*pi));
It will print 31.4 instead of 31.400000000000002
0
222
17 四月 2021, 01:49
Your computer does not save floating point numbers directly, but takes the floating point number *2 and subtracts 1 before bringing the result into a new round of calculations, and pi with this calculation results in an infinite number of bits, while the double type has a limit on the number of decimal places saved, so the result is 31.400000000000002 (this is a machine flip)
0