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

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("		1:按年投资
		2:按月投资
");
    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("输入有误!
");
    }

}



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);
}

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