私は大学のコースの1つでJavaを学んでおり、forループを12回繰り返すごとにプログラムの出力を一時停止する方法を知る必要があります。360回繰り返すループがあり、12項目ごとに、キーが押されるまでループが出力を停止するように出力したいと思います。私はかなりの検索を行いましたが、見つけたものはすべてはるかに高度なコンテキストにあり、コードで他に何が起こっているのか完全には理解していませんでした。このプログラムにはGUIがなく、非常に単純なので、ここにすべてのコードを貼り付けることができます。
public class MyMain
{
static double principal = 200000.00;
static double interest = .0575;
static int term = 360;
static DecimalFormat currency = new DecimalFormat("###,###.##");
public static void main(String[] args)
{
MortgageCalculator mortgageWeek2 = new MortgageCalculator(principal, interest, term);
double monthlyPayment = mortgageWeek2.calculate();
System.out.println("Welcome to my Mortgage Calculator.");
System.out.println("The principal on this loan is $" + currency.format(principal) + ".");
System.out.println("The interest on this loan is " + (interest * 100) + "%.");
System.out.println("The term on this loan is " + term + " months (" + term / 12 + " years).");
System.out.println("Payments on this loan will be $" + currency.format(monthlyPayment));
double balanceRemaining = 200000.0;
for (int i = 0; i < 30 * 12; i++)
{
double interestPaid = balanceRemaining * .0575 / 12;
double principalPaid = monthlyPayment - interestPaid;
balanceRemaining = balanceRemaining - principalPaid;
System.out.println("Month " + (i + 1) + " \tPayment Amount: $" + currency.format(monthlyPayment) +
"\tInterest Paid: $" + currency.format(interestPaid) +
" \tPrincipal Paid: $" + currency.format(principalPaid) +
" \tBalance Remaining: $" + currency.format(balanceRemaining));
}
}
}