码迷,mamicode.com
首页 > 编程语言 > 详细

复利计算C语言转java的相关代码

时间:2016-03-29 14:38:03      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

static void principal()// 计算本金
{
    int N, m;
    double i, F, P;
    System.out.printf("复利终值:");
    F = scanner.nextDouble();
    System.out.printf("年利率:");
    i = scanner.nextDouble();
    System.out.printf("存入年限:");
    N = scanner.nextInt();
    System.out.printf("年复利次数:");
    m = scanner.nextInt();
    //P = capital_formula(F, i, N, m);
    P = F / Math.pow((1 + i / m), N * m);
    System.out.println("年复利终值为" + F + "需要本金为:" + P);
}



static void Year_end_value()// 计算复利终值
{
    int N, m;
    double i, F, P;
    System.out.printf("存入本金:");
    P = scanner.nextDouble();
    System.out.printf("年利率:");
    i = scanner.nextDouble();
    System.out.printf("存入年限:");
    N = scanner.nextInt();
    System.out.printf("年复利次数:");
    m = scanner.nextInt();
    F = P * Math.pow((1 + i / m), N * m);
    System.out.println("复利终值:" + F);
}



static void danli()// 单利计算
{
    int N;
    double i, F, P;
    System.out.printf("存入本金:");
    P = scanner.nextDouble();
    System.out.printf("年利率:");
    i = scanner.nextDouble();
    System.out.printf("存入年限:");
    N = scanner.nextInt();
    F = P + P * N * i;
    System.out.println("本息和为:" + F);
}


static void years()// 求年份
{
    int year, m;
    double i, F, P;
    System.out.printf("复利终值:");
    F = scanner.nextDouble();
    System.out.printf("存入本金:");
    P = scanner.nextDouble();
    System.out.printf("年利率:");
    i = scanner.nextDouble();
    System.out.printf("年复利次数:");
    m = scanner.nextInt();
    year = (int) (Math.log(F / P) / Math.log(1 + i / m) / m);
    System.out.println("" + P + "" + F + "需要" + year + "");
}



static void APY()// 计算年利率
{
    int N, m;
    double rate, F, P;
    System.out.printf("复利终值:");
    F = scanner.nextDouble();
    System.out.printf("存入本金:");
    P = scanner.nextDouble();
    System.out.printf("存入年限:");
    N = scanner.nextInt();
    System.out.printf("年复利次数:");
    m = scanner.nextInt();
    rate = m * (Math.pow(F / P, 1.0 / (N * m)) - 1);
    System.out.println("" + P + "" + F + "需要" + rate);
}



static void Investment()// 计算等额投资
{
    int N, n;
    double i, final_value, P;
    System.out.printf("\t\t1:按年投资\n\t\t2:按月投资\n");
    System.out.printf("请选择你要的功能<1|2>:");
    n = scanner.nextInt();
    if (n == 1) {
        System.out.printf("存入本金:");
        P = scanner.nextDouble();
        System.out.printf("存入年限:");
        N = scanner.nextInt();
        System.out.printf("年利率:");
        i = scanner.nextDouble();
        final_value = P * (Math.pow(1 + i, N) - 1) / i;
        System.out.println(N + "年后的总产值:" + final_value);

    } else if (n == 2) {
        System.out.printf("存入本金:");
        P = scanner.nextDouble();
        System.out.printf("存入年限:");
        N = scanner.nextInt();
        System.out.printf("年利率:");
        i = scanner.nextDouble();
        final_value = P * 12 * (1 + i) * (Math.pow(1 + i, N) - 1) / i;
        System.out.println(N + "年后的总产值:" + final_value);
    } else {
        System.out.printf("输入有误!\n");
    }

}



static void Repayment()// 等额还款
{
    int N;
    double i, F, refund;
    System.out.printf("贷款金额:");
    F = scanner.nextDouble();
    System.out.printf("存入年限:");
    N = scanner.nextInt();
    System.out.printf("年利率:");
    i = scanner.nextDouble();
    refund = F * i / (12 * (1 + i) * (Math.pow(1 + i, N) - 1));
    System.out.println("贷款" + F + "每月需要还款" + refund);
}

}

 

复利计算C语言转java的相关代码

标签:

原文地址:http://www.cnblogs.com/4249ken/p/5332599.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!