java语言程序设计(基础篇)第十版编程练习题[1.11]

本文介绍了一个基于美国人口调查局假设的人口估算程序,该程序计算了未来五年内每年的人口数,考虑了出生率、死亡率和移民率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

*(人口估算)美国人口调査局基于以下假设进行人口估算:
●每 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);
        
    }
    
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值