zoukankan      html  css  js  c++  java
  • 计算贴现率相关问题

    package test;

    import java.math.BigDecimal;

    public class test1 {

        public static void main(String[] args) {

            int[] project1=new int[]{-100000,10000,10000,10000,20000,100000};

            int[] project2=new int[]{-1000000,200000,200000,200000,200000,300000};

            int[] project3=new int[]{-100000,30000,30000,30000,30000,30000};

            int[] project4=new int[]{-120000,30000,30000,30000,30000,75000};

            double[] tiexian=new double[]{0.08,0.12};

            double[][] b=new double[2][6];

            //int project1result1=jia(project1,tiexian);

            for(int j=0;j<2;j++){

            for(int i=0;i<6;i++){

                b[j][i]=1/Math.pow((tiexian[j]+1), i);

                BigDecimal t = new BigDecimal(b[j][i]);

                b[j][i]=t.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();

            }

            }

            for(int j=0;j<2;j++){

                for(int i=0;i<6;i++){

                    if(j==0){

                    System.out.println("第"+i+"年"+"贴现率8%的贴现因子"+b[j][i]);

                    }else{

                    System.out.println("第"+i+"年"+"贴现率12%的贴现因子"+b[j][i]);

                    }

                        

                }

                }

            int[] project1result1=doit(project1,b);System.out.println("项目1中贴现率8%的净现值:"+project1result1[0]+"   贴现率12%的净现值:"+project1result1[1]);

            int[] project1result2=doit(project2,b);System.out.println("项目2中贴现率8%的净现值:"+project1result2[0]+"   贴现率12%的净现值:"+project1result2[1]);

            int[] project1result3=doit(project3,b);System.out.println("项目3中贴现率8%的净现值:"+project1result3[0]+"   贴现率12%的净现值:"+project1result3[1]);

            int[] project1result4=doit(project4,b);System.out.println("项目4中贴现率8%的净现值:"+project1result4[0]+"   贴现率12%的净现值:"+project1result4[1]);

            

        }

        static int[] doit(int[] a, double[][] b){

            int[] p=new int[2];

            for(int j=0;j<2;j++){

                int temp=0;

            for(int i=0;i<6;i++){

                temp=(int)(temp+a[i]*b[j][i]);

                System.out.println(temp+"-----");

            }

            p[j]=temp;

            }

            //System.out.println("8%的净现值:"+p[0]+"    12%的净现值:"+p[1]);

            return p;

            }

    }

     

  • 相关阅读:
    Python 使用正则表达式匹配URL网址
    第3章 网络爬虫基础
    《精通Python网络爬虫》
    /etc/hosts
    Linux alias 命令
    file()
    Win10 取消桌面快捷键图标
    Win10 我的电脑 -- 右键点击管理打不开
    MongoDB 备份恢复
    ORACLE 日期比较
  • 原文地址:https://www.cnblogs.com/Lhxxx/p/14941150.html
Copyright © 2011-2022 走看看