public class Repay { static int amountB(int c, double r, int n) { //n年目の元金cの元利合計 return (int)amount(c, r, n); } static int amountC(int x, double r, int n) { //(n年間の)返済額xの元利合計 double c=0; for(int i=1; i<=n; i++) c += amount(x, r, i); return (int)c; } static double amount(int c, double r, int n) { //元利合計・理論値 return c*Math.pow((1+r), n); } static int repay(int c, double r, int n) {//毎年の返済額 int x = c/n; int total = amountB(c, r, n); while(amountC(x,r,n-1)+x<total)x++; return (int)x; } public static void main(String[] args) { int c, n; double r; c = Integer.parseInt(args[0]); r = Integer.parseInt(args[1])/100.0; n = Integer.parseInt(args[2]); System.out.printf("毎年の返済額 %d\n", repay(1000000, 0.05, 10)); } }
cが借入額で、rが年利で、 nが年数を表しています。
上のプログラムのrepayメソッドで分からないところがあります。(毎年の返済額と書いてありますが、、、)
まず、xというのは「(利息を含めない)毎年の返済額」で、totalというのは「n年目の返済額」という解釈であってますか?あとwhile文の中身とx++の意味もよく分からないです。一体何をしているのでしょうか。
このプログラムを書いた人にきくのが一番良いのですが、きくことが困難なのでぜひ力を貸して欲しいです。どうぞ宜しくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。