净现值计算
import java.util.*;标签:int,每日,博客,public,static,现值,npv,sum From: https://www.cnblogs.com/LiuLyuancn/p/18067748
public class jis {
static Scanner in = new Scanner(System.in);
public static void input(int a[], int n) {//数组输入
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
}
public static int[] year_npv(int c[], int d[], double r)// 计算年净现值并存入数组
{
for (int t = 0; t < c.length; t++) {
d[t] = (int) (c[t] / (Math.pow(1 + r, t)));
}
return d;
}
public static int sum_npv(int e[])// 计算最终净现值
{
int sum = 0;
for (int i = 0; i < e.length; i++) {
sum += e[i];
}
return sum;
}
public static void main(String[] args) {
int a[] = new int[6];// 项目的年金额数组
int b[] = new int[6];// 年净现值数组
for (int i = 1; i <= 4; i++) {
System.out.println("请输入项目" + i + "每年的金额:");
input(a, 6);
int npv1 = sum_npv(year_npv(a, b, 0.08));
int npv2 = sum_npv(year_npv(a, b, 0.12));
System.out.println("项目的净现值为:贴现率8%:" + npv1 + " 贴现率12%:" + npv2);
System.out.println();
}
}
}