• 算复利条件下等额还款金额


      1 import java.util.Scanner;
      2 
      3 public class exercise {
      4 
      5     public static void main(String[] args) {
      6         int select;
      7         do {
      8             System.out.println("请问您想要进行单利计算还是复利计算:1.单利 2.复利");
      9             Scanner keyin0 = new Scanner(System.in);
     10             select = keyin0.nextInt();
     11         } while (select != 1 && select != 2);
     12         System.out.println("请输入您想要存储的金额数量:");
     13         Scanner keyin1 = new Scanner(System.in);
     14         double originalMoney = keyin1.nextDouble();
     15         System.out.println("请输入您想要存储金额的时间(年):");
     16         Scanner keyin2 = new Scanner(System.in);
     17         int year = keyin2.nextInt();
     18         System.out.println("请输入您想要设计的年利率:");
     19         Scanner keyin3 = new Scanner(System.in);
     20         double rate = keyin3.nextDouble();
     21         double sumValue = originalMoney;
     22         if (select == 1) {
     23             double singleValue = originalMoney * (1 + rate * year);
     24             System.out.println("存入第" + year + "年后的存款总额为:" + singleValue);
     25             do {
     26                 System.out.println("请问您想要计算本金问题吗:1.需要 2.不需要");
     27                 select = new Scanner(System.in).nextInt();
     28             } while (select != 1 && select != 2);
     29             if (select == 1) {
     30                 System.out.println("请输入您想要筹到的金额:");
     31                 singleValue = new Scanner(System.in).nextDouble();
     32                 System.out.println("请输入您想要存储金额的时间(年):");
     33                 year = new Scanner(System.in).nextInt();
     34                 System.out.println("请输入您想要设计的年利率:");
     35                 rate = new Scanner(System.in).nextDouble();
     36                 originalMoney = singleValue / (1 + rate * year);
     37                 System.out.println("需要本金" + originalMoney + "元");
     38             }
     39         } 
     40         else {
     41             for (int i = 1; i <= year; i++) {
     42                 sumValue = (1 + rate) * sumValue;
     43 
     44             }
     45             System.out.println("存入第" + year + "年后的存款总额为:" + sumValue);
     46             do {
     47                 System.out.println("请问您想要计算本金问题吗:1.需要 2.不需要");
     48                 select = new Scanner(System.in).nextInt();
     49             } while (select != 1 && select != 2);
     50             if (select == 1) {
     51                 System.out.println("请输入您想要筹到的金额:");
     52                 sumValue = new Scanner(System.in).nextDouble();
     53                 System.out.println("请输入您想要存储金额的时间(年):");
     54                 year = new Scanner(System.in).nextInt();
     55                 System.out.println("请输入您想要设计的年利率:");
     56                 rate = new Scanner(System.in).nextDouble();
     57                 for (int i = 1; i <= year; i++) {
     58                     sumValue = sumValue / (1 + rate);
     59 
     60                 }
     61                 originalMoney = sumValue;
     62                 System.out.println("需要本金" + originalMoney + "元");
     63             }
     64             do {
     65                 System.out.println("请问您想要计算时间问题吗:1.需要 2.不需要");
     66                 select = new Scanner(System.in).nextInt();
     67             } while (select != 1 && select != 2);
     68             if (select == 1) {
     69                 System.out.println("请输入您想要存储的金额数量:");
     70                 originalMoney = new Scanner(System.in).nextDouble();
     71                 System.out.println("请输入到期后您想要获取的金额:");
     72                 sumValue = new Scanner(System.in).nextDouble();
     73                 System.out.println("请输入您想要设计的年利率:");
     74                 rate = new Scanner(System.in).nextDouble();
     75                 year = 1;
     76                 for (; sumValue > originalMoney; year++) {
     77                     originalMoney = originalMoney * (1 + rate);
     78 
     79                 }
     80                 year--;
     81                 System.out.println("需要" + year + "年时间");
     82             }
     83             do {
     84                 System.out.println("请问您想要计算利率问题吗:1.需要 2.不需要");
     85                 select = new Scanner(System.in).nextInt();
     86             } while (select != 1 && select != 2);
     87         //}while (select != 1 && select != 2);
     88         if (select == 1) {
     89             System.out.println("请输入您想要存储的金额数量:");
     90             originalMoney = new Scanner(System.in).nextDouble();
     91             System.out.println("请输入到期后您想要获取的金额:");
     92             sumValue = new Scanner(System.in).nextDouble();
     93             System.out.println("请输入您想要存储金额的时间(年):");
     94             year = new Scanner(System.in).nextInt();
     95             rate = 0;
     96             for (; Math.log(sumValue / originalMoney) / Math.log(rate + 1) > year; rate = rate + 0.0001) {
     97                 continue;
     98             }
     99             System.out.println("年利率应为:" + rate);
    100 
    101         }
    102         do {
    103             System.out.println("请问您想要计算每年或者每月拿出固定金额投资吗:1.需要 2.不需要");
    104             select = new Scanner(System.in).nextInt();
    105         } while (select != 1 && select != 2);
    106         if(select==1){
    107             do {
    108                 System.out.println("请问您想要投资额是以月计算还是以年计算:1.月 2.年");
    109                 select = new Scanner(System.in).nextInt();
    110             } while (select != 1 && select != 2);
    111             if(select==1){
    112                 System.out.println("请问您想每个月定期投资多少:");
    113                 originalMoney = new Scanner(System.in).nextDouble();
    114                 System.out.println("请输入您想要设计的月利率:");
    115                 double rateMonth = new Scanner(System.in).nextDouble();
    116                 System.out.println("请输入您想要存储金额的时间(月):");
    117                 int month = new Scanner(System.in).nextInt();
    118                 sumValue=0;
    119                 for (int i = 1; i <= month; i++) {
    120                     sumValue = (1 + rateMonth) * (sumValue+originalMoney);
    121 
    122                 }
    123                 System.out.println(""+month+"个月后资产总值将变为:"+sumValue);
    124             }
    125             if(select==2){
    126                 System.out.println("请问您想每年定期投资多少:");
    127                 originalMoney = new Scanner(System.in).nextDouble();
    128                 System.out.println("请输入您想要设计的年利率:");
    129                 rate = new Scanner(System.in).nextDouble();
    130                 System.out.println("请输入您想要存储金额的时间(年):");
    131                 year = new Scanner(System.in).nextInt();
    132                 sumValue=0;
    133                 for (int i = 1; i <=year; i++) {
    134                     sumValue = (1 + rate) * (sumValue+originalMoney);
    135 
    136                 }
    137                 System.out.println(""+year+"年后资产总值将变为:"+sumValue);
    138             }
    139         }
    140         do {
    141             System.out.println("请问您想要计算贷款问题吗:1.需要 2.不需要");
    142             select = new Scanner(System.in).nextInt();
    143         } while (select != 1 && select != 2);
    144         if(select==1)
    145         {
    146             System.out.print("请输入贷款金额:");
    147             originalMoney=new Scanner(System.in).nextDouble();
    148             System.out.print("请输入贷款的时间期限(年):");
    149             year=new Scanner(System.in).nextInt();
    150             System.out.print("请输入贷款的年利率:");
    151             rate=new Scanner(System.in).nextDouble();
    152             sumValue=originalMoney;
    153             for (int i = 1; i <= year; i++) {
    154                 sumValue = (1 + rate) * sumValue;
    155 
    156             }
    157             
    158             double returnPay=sumValue/(year*12);
    159             System.out.println("每个月应该偿还"+returnPay);
    160             
    161         }
    162 
    163     }
    164 
    165 }
    166 }

  • 相关阅读:
    CentOS下添加sudo用户
    CentOS查看你是否有USB 3.0端口
    CentOS查看操作系统信息(重要)
    JStack分析cpu消耗过高问题
    Java内存管理和垃圾回收
    kafka学习之-深入研究原理
    kafka学习之-文件存储机制
    kafka学习之-配置详解
    Hbase学习之javaApI封装
    linux中top命令
  • 原文地址:https://www.cnblogs.com/57rongjielong/p/5295774.html
Copyright © 2020-2023  润新知