185k views
5 votes
The US 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 the current population is 312032486 and one year has 365 days.

1 Answer

5 votes

Answer:

The required code is given below with appropriate comments for better understanding

Step-by-step explanation:

public class Population

{

public static void main(String[] args)

{

int currentPopulation=312032486;

int numSecInyear=24*60*60*365;//for one day 24 hours,60 min,60 sec

System.out.println("current population:"+currentPopulation);

int numBirths=numSecInyear/7;

int numDeaths=numSecInyear/13;

int numImmigrant=numSecInyear/45;

//print the result using for loop

for(int i=1;i<=5;i++){

currentPopulation=currentPopulation+numBirths-numDeaths+numImmigrant;//add up births and immigrants, remove deaths

System.out.println("Population After year-"+i+":"+currentPopulation);

}

}

}

User Mcamara
by
4.3k points