• 单利计算与复利计算程序


     1 import java.util.Scanner;
     2 
     3 
     4 public class exercise {
     5 
     6     public static void main(String[] args) {
     7         int select;
     8         do{
     9         System.out.println("请问您想要进行单利计算还是复利计算:1.单利 2.复利");
    10         Scanner keyin0=new Scanner(System.in);
    11         select=keyin0.nextInt();
    12         }while(select!=1&&select!=2);
    13         System.out.println("请输入您想要存储的金额数量:");
    14         Scanner keyin1=new Scanner(System.in);
    15         double originalMoney=keyin1.nextDouble();
    16         System.out.println("请输入您想要存储金额的时间(年):");
    17         Scanner keyin2=new Scanner(System.in);
    18         int year=keyin2.nextInt();
    19         System.out.println("请输入您想要设计的年利率:");
    20         Scanner keyin3=new Scanner(System.in);
    21         double rate=keyin3.nextDouble();
    22         double sumValue=originalMoney;
    23         if(select==1)
    24         {
    25             double singleValue=originalMoney*(1+rate*year);
    26             System.out.println("存入第"+year+"年后的存款总额为:"+singleValue);
    27             do{
    28                 System.out.println("请问您想要计算本金问题吗:1.需要 2.不需要");
    29                 select=new Scanner(System.in).nextInt();
    30                 }while(select!=1&&select!=2);
    31             if(select==1){
    32                 System.out.println("请输入您想要筹到的金额:");
    33                 singleValue=new Scanner(System.in).nextDouble();
    34                 System.out.println("请输入您想要存储金额的时间(年):");
    35                 year=new Scanner(System.in).nextInt();
    36                 System.out.println("请输入您想要设计的年利率:");
    37                 rate=new Scanner(System.in).nextDouble();
    38                 originalMoney=singleValue/(1+rate*year);
    39                 System.out.println("需要本金"+originalMoney+"元");
    40             }
    41         }
    42         else
    43         {
    44         for(int i = 1 ; i<=year; i++){
    45                sumValue= (1+ rate)*sumValue; 
    46               
    47         }
    48         System.out.println("存入第"+year+"年后的存款总额为:"+sumValue);
    49         do{
    50             System.out.println("请问您想要计算本金问题吗:1.需要 2.不需要");
    51             select=new Scanner(System.in).nextInt();
    52             }while(select!=1&&select!=2);
    53         if(select==1){
    54             System.out.println("请输入您想要筹到的金额:");
    55             sumValue=new Scanner(System.in).nextDouble();
    56             System.out.println("请输入您想要存储金额的时间(年):");
    57             year=new Scanner(System.in).nextInt();
    58             System.out.println("请输入您想要设计的年利率:");
    59             rate=new Scanner(System.in).nextDouble();
    60             for(int i = 1 ; i<=year; i++){
    61                    sumValue= sumValue/(1+ rate); 
    62                   
    63             }
    64             originalMoney=sumValue;
    65             System.out.println("需要本金"+originalMoney+"元");
    66         }
    67         do{
    68             System.out.println("请问您想要计算时间问题吗:1.需要 2.不需要");
    69             select=new Scanner(System.in).nextInt();
    70             }while(select!=1&&select!=2);
    71         if(select==1){
    72             System.out.println("请输入您想要存储的金额数量:");
    73             originalMoney=new Scanner(System.in).nextDouble();
    74             System.out.println("请输入到期后您想要获取的金额:");
    75             sumValue=new Scanner(System.in).nextInt();
    76             System.out.println("请输入您想要设计的年利率:");
    77             rate=new Scanner(System.in).nextDouble();
    78             year=1;
    79             for(; sumValue>originalMoney;year++){
    80                 originalMoney= originalMoney*(1+ rate); 
    81                   
    82             }
    83             year--;
    84             System.out.println("需要"+year+"年时间");
    85         }
    86         
    87         
    88         
    89         }
    90 
    91     }
    92 
    93 }

                  

  • 相关阅读:
    9. MySQL
    python第四课
    python第三课pycharm的使用
    python第二课
    python第一课
    Python3基础-网络编程(8)
    Python3基础-异常处理(7)
    Python3基础-面向对象(6)
    Python3基础-模块和包(5)
    Python3基础-文件处理(4)
  • 原文地址:https://www.cnblogs.com/57rongjielong/p/5269634.html
Copyright © 2020-2023  润新知