zoukankan      html  css  js  c++  java
  • 复利计算1.0

    import java.text.DecimalFormat;
    import java.util.Scanner;
    
    public class fulijisuanqi01 {
        static Scanner scanner = new Scanner(System.in);
        static DecimalFormat df = new DecimalFormat("####0.0000");
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
    
            System.out.println("1.复利计算;");
            System.out.println("2.单利计算;");
            System.out.println("3.本金计算;");
            System.out.println("4.年限计算。"); 
         System.out.println(
    "请选择:");
    int k = scanner.nextInt(); switch (k) { case 1: fulijisuan(); break; case 2: danlijisuan(); break; case 3: benjinjisuan(); break; case 4: nianxianjisuan(); default: break; } } private static void nianxianjisuan() { // TODO Auto-generated method stub System.out.println("本金是:"); double P = scanner.nextDouble(); System.out.println("利率是:"); double i = scanner.nextDouble(); System.out.println("复利终值是:"); double F = scanner.nextDouble(); int n = (int) (Math.log(F / P) / Math.log(1 + i)); System.out.println("年限是:" + n); } private static void benjinjisuan() { // TODO Auto-generated method stub System.out.println("复利终值是:"); double F = scanner.nextDouble(); System.out.println("利率是:"); double i = scanner.nextDouble(); System.out.println("年限是:"); int n = scanner.nextInt(); double P; P = F / Math.pow(1 + i, n); String p = df.format(P); System.out.println("本金是:" + p); } private static void danlijisuan() { // TODO Auto-generated method stub System.out.println("本金是:"); double P = scanner.nextDouble(); System.out.println("利率是:"); double i = scanner.nextDouble(); System.out.println("年限是:"); int n = scanner.nextInt(); double F; F = P * (1 + i * n); String f = df.format(F); System.out.println("单利终值是:" + f); } private static void fulijisuan() { System.out.println("本金是:"); double P = scanner.nextDouble(); System.out.println("利率是:"); double i = scanner.nextDouble(); System.out.println("年限是:"); int n = scanner.nextInt(); double F; F = P * Math.pow(1 + i, n); String f = df.format(F); System.out.println("复利终值是:" + f); } }


    功能:
    1.可以通过本金计算复利终值;
    2.可以通过复利终值计算本金;
    3.可以通过本金计算单利终值;
    4.可以通过本金和复利终值计算存储年限。
  • 相关阅读:
    系统设计的一些原则
    分层开发思想与小笼包
    工作与生活
    Microsoft .NET Pet Shop 4 架构与技术分析
    用人之道(二) 如何管理软件开发团队
    也谈很多开发人员的毛病
    《3S新闻周刊》第10期,本期策划:“超女”营销带来的启示
    浅析ArcIMS
    MapX的坐标问题
    应用ArcIMS构建GMap风格的地图应用
  • 原文地址:https://www.cnblogs.com/wangzekai/p/5268741.html
Copyright © 2011-2022 走看看