我正在为我的Java课程制作一个程序,它可以计算从起始年份(2011年)开始每年增长1.2%的人口数量。2011年的人口为7,000(我使用小数,而不是十亿)。我目前有这段代码。
int startYear = 2011;
int endYear = user_input.nextInt();
double t = 1.2; //Population percent increase anually
double nbr = (endYear - startYear); //Number of years increased
double pStart = 7.000; //Starting population of 2011
double pEnd = pStart * Math.exp(nbr * t); // Ending population of user input
DecimalFormat nf = new DecimalFormat("2");
System.out.println("Population in " + endYear + ": " (nf.format(pEnd)));
代码没有错误,一切都可以运作,但是我在pEnd方程上遇到了麻烦。当前,当我输入2016作为结束年份时,我得到22824的结果。我尝试过在Google上搜索公式,但是我找不到任何有用的内容。你们中的任何人有这个公式的想法吗?如果你输入2016作为结束年份,它应该大约是7.433
exp(double a):返回以双精度值a为底数的自然指数e的幂次方结果。
您确定这是您想要的吗? - tkausl