*(人口估算)美国人口调査局基于以下假设进行人口估算:
●每 7 秒有一个人诞生
●每 13 秒有一个人死亡
●每 45 秒有一个移民迁入
编写一个程序,显示未来5年的每年的人口数。假设当前的人口是 312032486, 每年有365天。提示:Java中,两个整数相除,结果还是整数,小数部分被去掉。例如,5/4 等于1 (而不是1.25 ), 10/4 等于2(而不是2.5 )。如果想得到有小数部分的精确结果,进行除法运算的两个值之一必须是一个具有小数点的数值。例如,5.0/4等于1.25, 10/4.0等于2.5。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dome1_11;
/**
*
* @author Administrator
*/
public class Dome1_11 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int second = 0;
int nowpeople = 312032486;
second = 365 * 24 * 60 * 60;
double birth = second / 7;
double death = second / 13;
double immigrant = second / 45;
int second = 0;
int nowpeople = 312032486;
second = 365 * 24 * 60 * 60;
double birth = second / 7.0;
double death = second / 13.0;
double immigrant = second / 45.0;
int oneyears = (int)(birth - death + immigrant);
int Firstyear = nowpeople + 1 * oneyears;
int Secondyears = nowpeople + 2 * oneyears;
int Thethirdyear = nowpeople + 3 * oneyears;
int Fourthyear = nowpeople + 4 * oneyears;
int Fifthyears = nowpeople + 5 * oneyears;
System.out.println(Firstyear);
System.out.println(Secondyears);
System.out.println(Thethirdyear);
System.out.println(Fourthyear);
System.out.println(Fifthyears);
System.out.println(Firstyear);
System.out.println(Secondyears);
System.out.println(Thethirdyear);
System.out.println(Fourthyear);
System.out.println(Fifthyears);
}
}