我目前正在為大學做軟件基礎教程,而我目前仍在解決這個問題?!坝嬎忝磕暝阢y行帳戶中獲得指定金額的款項所需的年數,假設在每年年底支付利息,并且不提取任何款項。該程序應提示用戶輸入當前余額以磅為單位,所需的余額以磅為單位,利率以百分比表示。然后,它應計算并輸出達到所需余額所需的年數,并在每年年底輸出當前余額?!钡侥壳盀橹?,我已經嘗試過了,也嘗試過移動變量,但是它始終會導致無限循環。如何停止呢?package interest;import java.util.Scanner;public class Interest { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("hello what is your current balance ?"); double balance = input.nextDouble(); System.out.println("What is your required Balance"); Double requiredBal = input.nextDouble(); System.out.println("what is your current interest rate in %"); double interest = input.nextDouble(); int years = 0; double totalbalance=0; do { double intbalance = (balance /100) * interest; totalbalance = balance + intbalance; years ++; System.out.println("your balance after " + years +" years = " + totalbalance); }while(totalbalance <= requiredBal); System.out.println("it will take" + years + " years to get to " + requiredBal); }}它應該是這樣的enter current balance100enter required balance200enter interest rate 10balance after 1 year = 110.0 balance after 2 year = 120.0 balance after 3 year = 130.0 balance after 4 year = 140.0balance after 5 year = 150.0 balance after 6 year = 160.0 balance after 7 year = 170.0balance after 8 year = 180.0balance after 9 year = 190.0 balance after 10 year = 200.0It will take 10 years to reach the required balance.
2 回答

弒天下
TA貢獻1818條經驗 獲得超8個贊
讓我們做一些嬰兒數學。
指數增長被定義為y=a(1+r)^x
其中a
是初始值和r
是的興趣(0和1之間)。此功能可映射X年的銀行帳戶余額。我們想要逆。
如果對這個方程求逆,則得到y=logx/(log[a(1+r)]
。x
如果您可以進行一點數學運算,它將告訴您多少年才達到不需要循環的平衡。
添加回答
舉報
0/150
提交
取消