# 计算贷款支付额

2022-05-08 16:02:00  阅读：50  来源： 互联网

# 计算贷款支付额

## 月支付额 = 贷款总额月利率 /（1-1/（1+月利率）^(年数12））

``````import java.util.Scanner;
class Main {
public static void main(String[] args) {
//Create a Scanner
Scanner input = new Scanner(System.in);

//Enter yearly interest rate
System.out.print("请输入年利率，比如 4.5：");
double annualInterestRate = input.nextDouble();

//Obtain monthly interest rate
double monthlyInterestRate = annualInterestRate / 1200;

//Enter number of years
System.out.print("请输入年数，比如 5：");
int numberOfYears = input.nextInt();

//Enter loan amount
System.out.print("请输入贷款总额，比如 300000：");
double loanAmount = input.nextDouble();

//Calculate payment
double monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1/Math.pow(1 +     monthlyInterestRate,numberOfYears * 12));
double totalPayment = monthlyPayment * numberOfYears * 12;

//Display results
System.out.println("每月还款：" + (int)(monthlyPayment * 100) / 100.0);
System.out.println("还款总额：" + (int)(totalPayment * 100) / 100.0);

input.close();
}
}``````