【发布时间】:2020-10-09 05:34:18
【问题描述】:
我需要这个特定的行是 2 个小数点。
System.out.println(i + "\t\t" + interest + "\t\t" + principal + "\t\t" + balance);
我的整个代码是
import java.util.Scanner;
public class assignment5dot22 {
public static void main(String[] args) {
int numberOfYears;
double loanAmount;
double annualInterest;
double monthlyInterest;
double monthlyPayment;
double principal;
double balance;
double interest;
Scanner input = new Scanner(System.in);
System.out.print("Loan Amount: ");
loanAmount = input.nextDouble();
System.out.print("Number of Years: ");
numberOfYears = input.nextInt();
System.out.print("Annual Interest Rate: ");
annualInterest = input.nextDouble();
monthlyInterest = annualInterest / 1200;
monthlyPayment = loanAmount*monthlyInterest / (1 - (Math.pow(1 / (1 + monthlyInterest),
numberOfYears * 12)));
balance = loanAmount;
System.out.println("Monthly Payment: "
+ (monthlyPayment * 100) / 100.0);
System.out.println("Total Payment: "
+ (monthlyPayment * 12 * numberOfYears * 100) / 100.0);
System.out.println("\nPayment#\tInterest\tPrincipal\tBalance");
for (int i = 1; i <= numberOfYears * 12; i++) {
interest = (monthlyInterest * balance);
principal = ((monthlyPayment - interest)*100) / 100.0;
balance = ((balance - principal) * 100) / 100.0;
System.out.println(i + "\t\t" + interest + "\t\t" + principal + "\t\t" + balance);
}
}
}
【问题讨论】:
标签: java