import java.util.*;
public class Project3{
public static void main(String[] args)
{
Scanner key = new Scanner (System.in);
double rate = 0.05;
double annually, monthly, daily;
double balance;
int year = 10 ;
System.out.println("Enter the amount you will like to deposit or type exit to end.");
int deposit = key.nextInt();
annually = deposit * Math.pow((1 + rate/1),year);
monthly = deposit * Math.pow((1 + rate/12),year);
daily = deposit * Math.pow((1 + rate/365),year);
while (deposit)
{
}
System.out.println(annually);
System.out.println(monthly);
System.out.println(daily);
}
}
這是我目前擁有的。我試圖完成的是做一個循環來添加下一個結果的第一個結果。也可以製作一個配方,而不是有三個配方來找到每年,每月和每天的配方。複利
請解釋你的意思是'做一個循環來添加第一個結果與下一個' – Harshit
「使用一個循環,增加每個時間段的興趣,也就是說,不要使用某種代數公式。你的程序應該有一個外部循環,允許用戶重新計算新的餘額和利率,重複計算直到用戶要求結束程序。「 – Luis
那麼,如果你想從循環的第一次迭代中添加一個值,那麼爲什麼不把它存儲在一個新的變量中呢?你將每個公式存儲在自己的變量中是正確的,除非我把它全部放在一行上。注意:如果這是作業,可以考慮請求你的老師幫忙。在QA網站上有人爲你寫作業是非常不道德的。 –