# Exercise 2.11 Solution - Population Projection

The program below is the answer to Liang's Introduction to Java Programming (9th Edition) Chapter 2 Exercise 2.11.

Question: Rewrite Exercise 1.11 to prompt the user to enter the number of years and displays the population after the number of years.

```/**
*
* @Author: Aghatise Osazuwa
* Website: www.cscprogrammingtutorials.com
*
* Exercise 2.11 - Population Projection
*
*/

import java.util.Scanner;

public class CalculatingEnergy {

public static void main(String[] args) {

//Display Program Information
System.out.println("This Program Calculates The Population In The "
+ "Specified Number Of Years' Time.\n");
System.out.println("Current population is assumed to be 312,032,486.\n");

//create Scanner
Scanner input = new Scanner(System.in);

//prompt user to enter details
System.out.println("Enter the number of years:");
int years = input.nextInt();

int currentPopulation = 312032486;
int births = 7;
int deaths = 13;
int immigrants = 45;

//calculate yearly births, yearly deaths and yearly immigrants
int yearlyBirths = (60 * 60 * 24 * 365) / births;
int yearlyDeaths = (60 * 60 * 24 * 365) / deaths;
int yearlyImmigrants = (60 * 60 * 24 * 365) / immigrants;

//calculate yearly population
int yearlyPopulation = (yearlyBirths + yearlyImmigrants) - yearlyDeaths;

//calculate population in the specified number of years
int population = currentPopulation + (yearlyPopulation * years);

//display the result
System.out.println("The population in " + years + " years is " + population + ".\n");
}
}
```

Click here to see other solutions to Introduction to Java Programming.