第一章第十一题(人口估算)(Population projection)

*1.11(人口估算)美国人口调查局基于以下假设进行人口估算:

  • 每7秒有一个人诞生
  • 每13秒有一个人死亡
  • 每45秒有一个移民迁入

编写一个程序,显示未来5年的每年人口数。假设当前的人口是312 032 486,每年有365天。提示:Java中,两个整数相除,结果还是整数,小数部分被去掉。例如,5/4等于1(而不是1.25),10/4等于2(而不是2.5)。如果想得到有小数部分的精确结果,进行除法运算的两个值之一必须是一个具有小数点的数值。例如,5.0/4等于1.25,10/4.0等于2.5。

*1.11 (Population projection) The U.S. Census Bureau projects population based on the following assumptions:

  • One birth every 7 seconds
  • One death every 13 seconds
  • One new immigrant every 45 seconds

Write a program to display the population for each of the next five years. Assume that the current population is 312,032,486, and one year has 365 days. Hint: In Java, if two integers perform division, the result is an integer. The fractional part is truncated. For example, 5 / 4 is 1 (not 1.25) and 10 / 4 is 2 (not 2.5). To get an accurate result with the fractional part, one of the values involved in the division must be a number with a decimal point. For example, 5.0 / 4 is 1.25 and 10 / 4.0 is 2.5.

下面是参考答案代码:

public class EstimatePopulationInFiveYearsQuestion11 
  • 5
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值