
/** * 题目名称人口增长问题 p * 题目来源http://noi.openjudge.cn/ch0105/14/ p * 程序功能计算指定年数后的人口总数 * * author 潘磊just_panleijust.edu.cn * version 1.0 */importjava.util.Scanner;publicclassMain{/** * 返回指定人口基数、年数、年增长率条件下最终的人口总数。 * * param base 指定人口基数。 * param year 指定年数。 * param rate 指定年增长率。 * return 最终的人口总数。 */publicdoublepopulation(intbase,intyear,doublerate){doubleansbase;// 最终的人口总数初始为人口基数/* 从第一年依次遍历到第year年 */for(inti1;iyear;i){ansans*rate;// 当年人口总数上年人口总数上年人口总数×年增长率}returnans;}publicstaticvoidmain(String[]args){MaincallnewMain();ScannerinputnewScanner(System.in);intxinput.nextInt();intninput.nextInt();System.out.printf(%.4f,call.population(x,n,0.001));}}/** * 题目名称人口增长问题 p * 题目来源http://noi.openjudge.cn/ch0105/14/ p * 程序功能计算指定年数后的人口总数 * * author 潘磊just_panleijust.edu.cn * version 1.1 */importjava.util.Scanner;publicclassMain{/** * 返回指定人口基数、年数、年增长率条件下最终的人口总数。 * * param base 指定人口基数。 * param year 指定年数。 * param rate 指定年增长率。 * return 最终的人口总数。 */publicdoublepopulation(intbase,intyear,doublerate){returnbase*Math.pow(1rate,year);// 计算并返回最终的人口总数}publicstaticvoidmain(String[]args){MaincallnewMain();ScannerinputnewScanner(System.in);intxinput.nextInt();intninput.nextInt();System.out.printf(%.4f,call.population(x,n,0.001));}}