您的位置:首页 > 编程语言 > C语言/C++

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

2016-03-29 13:18 429 查看
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);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: