//Calculate the amount of money you will receive based on your option
if (n == 0) {
while (death - 1 >= counter) {
System.out.format("Week %2d Linear: $%.2f Exponential: $%.2f\n", counter, a, p);
if ((death - 1 == counter) && (a >= p)) {
System.out.format("Your uncle dies in week %2d. But you were lucky and received an extra " +
"$%.2f dollars.\n", death, ((death * initial) - ((Math.pow(2, (death - 1))/100))));
}
if ((p > a) && (death - 1 >= counter)) {
System.out.format("Your uncle dies in week %2d. But you were unlucky and missed an extra " +
"$%.2f dollars.\n", death, (p - a));
}
a += initial;
counter++;
p = p * 2;
}
}
輸出:停止輸出處理
周1直線:$ 1.39的指數:$ 0.01
周2線性:$ 2.79的指數:$ 0.02
周3線性:$ 4.18的指數:$ 0.04
第4周線性:5.58美元指數:0.08美元
周5線性:$ 6.97的指數:$ 0.16
周6線性:$ 8.36的指數:$ 0.32
第7周線性:$ 9.76的指數:$ 0.64
第8周線性:$ 11.15指數:$ 1.28
第9周線性:$ 12.55指數:$ 2.56
第10周線性:$ 13.94指數:$ 5.12
第11周線性:$ 15.34指數:$ 10.24
第12周線性:$ 16.73指數:$ 20.48
你叔叔死在31星期,但你不走運,錯過了一個額外的 $ 3.75美元。
第13周線性:$ 18.12指數:$ 40.96
你叔叔死在31星期,但你不走運,錯過了一個額外的 $ 22.84美元。
第14周線性:$ 19.52指數:$ 81.92
你叔叔死在31星期,但你不走運,錯過了一個額外的 $ 62.40美元。
我的問題是我該如何阻止我的if語句,以便當p> a時它將停止輸出並說他已經死亡。在我的例子中的第12周,我希望它停止輸出並說他死了。
它幾乎如果十二點當p終於比我想提出一個更大的突破,但我真的不能把不等式說當p最終通過停止輸出 – donortiz
你真的應該解決您的壓痕。 – Zarwan
對不起,我剛開始使用java和這個網站.. – donortiz