I'm learning Java for one of my college courses, and I need to know how to pause the output of my program after every 12 iterations of a for loop. I have a loop that iterates 360 times, and I'd like for every 12 items the loop outputs the output to stop until a key is pressed. I have done quite a bit of searching, but everything I've found was in a much more advanced context and I didn't quite understand what else was going on in the code. There is no GUI for this program, and it is so simple that I could just paste all of the code here:
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));
}
}
}