I have a problem formatting my code to present the table properly and I am not sure how to fix it. Basically, the first row of numbers is not aligned properly to form columns like the rest. And how do I add the sign "%" at the end of the numbers under interest rate? Sorry, I tried to show what the output looks like here, but I cannot display it properly.
public class Boo {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Loan amount: ");
double loanAmount = in.nextInt();
System.out.println("Number of years: ");
int year = in.nextInt();
double monthlyPayment = 0;
double interestRate = 5.0;
final double INCREMENT = 0.125;
System.out.printf("%-20s %-20s %-20s", "Interest Rate", "Monthly Payment", "Total Payment\n");
for (int i = 0; i < year; i++) {
interestRate += INCREMENT; //increment by 0.125 every year
double monthlyInterestRate = interestRate / 1200;
monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / Math.pow(1 + monthlyInterestRate, year * 12));
double totalPayment = monthlyPayment * year * 12;
System.out.printf("%-20.3f %-20.2f %-20.2f\n", interestRate, monthlyPayment, totalPayment);
}
}
}