每日总结
代码:
import com.sun.tools.javac.Main;
import java.math.BigDecimal;
public class test {
public static void main(String[] args) {
float xm[][]={
{-100000,10000,10000,10000,20000,100000},
{-1000000,200000,200000,200000,200000,300000},
{-100000,30000,30000,30000,30000,30000},
{-120000,30000,30000,30000,30000,75000}
};
float r1 = (float) 0.08;
float r2 = (float) 0.12;
float num1[] = new float[6];
float num2[] = new float[6];
float sum1[] = {0,0,0,0};
float sum2[] = {0,0,0,0};
System.out.println("贴现率为:"+r1);
for (int i=0;i<6;i++){
num1[i] = Float.parseFloat(String.format("%.4f",(float) (1.0/Math.pow((1+r1),i))));
System.out.println("第"+i+"年的贴现因子:" +num1[i]);
}
for (int i=0;i<4;i++){
for (int j=0;j<6;j++){
sum1[i] += xm[i][j] * num1[j];
}
sum1[i] = Math.round(sum1[i]);
System.out.println("项目"+i+"的NPV为:"+ sum1[i]);
}
System.out.println("-----------------------------------------------------------------");
System.out.println("贴现率为:"+r2);
for (int i=0;i<6;i++){
num2[i] = Float.parseFloat(String.format("%.4f",(float) (1.0/Math.pow((1+r2),i))));
System.out.println("第"+i+"年的贴现因子:" +num2[i]);
}
for (int i=0;i<4;i++){
for (int j=0;j<6;j++){
sum2[i] += xm[i][j] * num2[j];
}
sum2[i] = Math.round(sum2[i]);
System.out.println("项目"+i+"的NPV为:"+ sum2[i]);
}
}
}
截图: