【问题标题】:I must give the programm an argument and it must make the root of it with the "heron process" also it must have 30 decimals我必须给程序一个参数,它必须用“苍鹭进程”作为它的根,它必须有 30 位小数
【发布时间】:2016-04-14 11:24:04
【问题描述】:
 public static BigDecimal bessereZieheWurzel(int zahl){
    BigDecimal bessereZahl = new BigDecimal(zahl);
    BigDecimal x = new BigDecimal(zahl);
    BigDecimal zwei = new BigDecimal(2);
    BigDecimal endErg = bessereZahl;
    BigDecimal zwischenErg = new BigDecimal(0);
    BigDecimal epsilon = new BigDecimal(0.000000000000000000000000000001);
    int anzahlSchritte = 1;
    BigDecimal variable = new BigDecimal(zahl);

    zwischenErg = bessereZahl.divide(x,30, RoundingMode.DOWN).add(x);

    zwischenErg = zwischenErg.divide(zwei,30, RoundingMode.DOWN);
    BigDecimal letzterDurchlauf = zwischenErg;
    x=zwischenErg;



    while(letzterDurchlauf.subtract(endErg).compareTo(epsilon) == 1);

    endErg = variable.divide(x,30, RoundingMode.DOWN).add(x);

    endErg = endErg.divide(zwei,30, RoundingMode.DOWN);


    anzahlSchritte ++;



      return endErg;     

我的问题是我的时间不对。我不知道那里有什么问题。如何更改时间以获得正确的结果?

【问题讨论】:

  • 您的while 为空。 while 需要一个块 { },你只是给了它一个空语句 ;

标签: c#


【解决方案1】:
while(letzterDurchlauf.subtract(endErg).compareTo(epsilon) == 1);

这行代码发生了什么?
答案是:什么都没有。绝对没有。
要解决此问题,请像这样运行:

while(letzterDurchlauf.subtract(endErg).compareTo(epsilon) == 1)
{
    //Stuff you want to run goes in here
}

现在您的 while 循环将正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    • 1970-01-01
    • 1970-01-01
    • 2014-01-23
    • 2022-06-11
    • 1970-01-01
    相关资源
    最近更新 更多