編寫一種方法來計算您在給定的年數內按特定利率償還貸款的每月還款額。該方法以年數t,本金P和年利率r爲參數。期望值由公式(P ert/12 t)給出。使用Math.exp()。該方法的簽名應爲:public static double monthlyPayment(double years, double principal, double rate)
使用該方法編寫程序支付可生成一組月度付款,這些付款可用於5年期間20,000美元的貸款,利率爲0.25%至5%之間,利率爲5%至8%增量。瞭解變化的含義
public class Payments {
public static void main(String[] args) {
for(double r=0.05; r<=0.08; r+=0.0025) {
System.out.println(monthlyPayment(5,20000,r));
}
}
public static double monthlyPayment(double years,double principal,double rate) {
return ((principal*(Math.exp(years*rate)))/(12*years));
}
}
這是我寫了這麼遠,我不知道該怎麼做其實我不被理解的平均值在0.25%的增量從5%變化到8%!有人可以解釋嗎?
不,我們不會幫助你做作業。 –
我想這是一個任務。你能標記作業的文本嗎? –
提供5%,5.25%,5.5%等等的結果,直到8%。 – Meesh