您好,登录后才能下订单哦!
密码登录
            
            
            
            
        登录注册
            
            
            
        点击 登录注册 即表示同意《亿速云用户服务条款》
        要求
根据贷款年限对应的不同利率计算月供
实现思路
1.创建一个月供类
2.在该类中,设定判定条件,不同的借款年限对应不同的月供
3.创建一个月供的实例,输入贷款年限和贷款金额测试
代码内容
月供类
public class MonthPay {
  public int total;//贷款总金额
  public int age; //贷款年限
  public void monthpay() {
    double monthpay;
    if (age<=3){
      monthpay = (6.03/100*total+total)/age;
    }else if(age <=5){
      monthpay = (6.12/100*total+total)/age;
    }else {
      monthpay = (6.39/100*total+total)/age;
    }
    System.out.println("***月供为"+monthpay/12);
  }
}
测试月供类
public class MonthPayTest {
  static Scanner sc = new Scanner(System.in);
  public static void main(String[] args) {
    MonthPay monthPay = new MonthPay();
    //选择贷款金额
    System.out.println("请输入贷款金额:");
    monthPay.total = sc.nextInt();
    System.out.println("请输入贷款年限:");
    monthPay.age = sc.nextInt();
    //计算月供
    monthPay.monthpay();
  }
}
运行结果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。