我的计算机类中有一个java问题,但没有任何意义。 [英] I have a java question in my computer class, but it makes no sense.
问题描述
编写一个名为<< yourname>>分配5的Java程序,将PI生成到用户定义的小数位(无四舍五入)。
确保使用Math.PI(PI为估计为:3.141592653589793)
如果用户选择选择5位小数,则输出应为:3.14159不是3.14160
另外
如果用户选择选择4位小数输出应该是:3.1415不是3.1416
我不知道怎么做!
我尝试过:
我不知道从哪里开始。我们从未在课堂上学到这一点,所以对我来说没有任何意义。
"Write a Java program named <<yourname>>Assign5 that generate PI to a user defined decimal places (No rounding).
Make sure you use Math.PI (PI is estimated as: 3.141592653589793)
If the user select to choose 5 decimal places the output should be: 3.14159 not 3.14160
Also
If the user select to choose 4 decimal places the output should be: 3.1415 not 3.1416"
I have no idea how to do this!
What I have tried:
I don't know where to start. We never learned this in class so it makes no sense to me.
推荐答案
我不知道从哪里开始。我们从来没有在课堂上学到这一点,所以对我来说没有任何意义。
I don't know where to start. We never learned this in class so it makes no sense to me.
实际上是有道理的。
以下例子描述了一种可能的算法: br />
假设您被要求提供两位小数。
从
开始
It actually makes sense.
A possible algorithm is described by the following example:
Suppose you're asked to provide two decimal digits.
Starting from
pi = 3.141592653589793
只取整数部分,即 3
然后将剩余数字乘以 10
,获得
take just the integer part, namely 3
then multiply the remaining number by 10
, obtaining
1.41592653589793
取整数部分,即 1
再迈出一步
take the integer part, namely 1
make another step
4.1592653589793
获取 4
。
结果是
obtaining 4
.
The result is
3.14
这篇关于我的计算机类中有一个java问题,但没有任何意义。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!