欢迎光临
我们一直在努力

3月13每日打卡

净现值计算的程序JAVA

import java.util.Scanner;

public class NPVCalculator {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print(“请输入投资项目的年限:”);
int years = input.nextInt();

double[] cashFlows = new double[years];
double discountRate, npv = 0;

System.out.println(“请输入每年的现金流量:”);
for (int i = 0; i < years; i++) {
cashFlows[i] = input.nextDouble();
}

System.out.print(“请输入贴现率:”);
discountRate = input.nextDouble();

for (int i = 0; i < years; i++) {
npv += cashFlows[i] / Math.pow((1 + discountRate), i + 1);
}

System.out.println(“该投资项目的净现值为:” + npv);

input.close();
}
}

 

未经允许不得转载:大有博文 » 3月13每日打卡
分享到: 更多 (0)

大前端WP主题 更专业 更方便

联系我们联系我们