净现值计算的程序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();
}
}
标签:13,int,每日,System,years,input,打卡,cashFlows,out From: https://www.cnblogs.com/yunbianshangdadun/p/18070103