复利计算C语言转java的相关代码
Posted 49陈焕恳
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了复利计算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("\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的相关代码的主要内容,如果未能解决你的问题,请参考以下文章