ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

计算贷款支付额

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

标签:Scanner int double 支付 System 计算 input 贷款 out


计算贷款支付额

月支付额 = 贷款总额月利率 /(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();
  }
}

标签:Scanner,int,double,支付,System,计算,input,贷款,out
来源: https://www.cnblogs.com/doudou-20123/p/16245801.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有