# Java World Population Growth Calculator

The program below is the answer to Deitel's Java How to Program (9th Edition) Chapter 2 Exercise 2.34.

Question: Use the web to determine the current world population and the annual world population growth rate. Write an application that inputs these values, then displays the estimated world population after one, two, three, four and five years.

```/**
*
* @Author: Aghatise Osazuwa
* Website: www.cscprogrammingtutorials.com
*
* Exercise 2.34 - World Population Growth Calculator
* This Program Calculates And Displays The Estimated World Population After One, Two, Three,
* Four And Five Years
*
*/

//Based on data from worldometer World Population clock (worldometers.info/world-population)
//Geohive (www.geohive.com/earth/population_now.aspx)
//US World Population Clock (www.census.gov/popclock)
//Current world population is 7,321,870,923 with an average yearly growth rate of 1.10%

import java.util.Scanner;

public class Ex02_34 {
public static void main (String [] args) {

Scanner input = new Scanner (System.in);

double currentPop;
double growthRate;
double annualPopIncrease;
double estimatedPop;

System.out.print ("Enter Current World Population: ");
currentPop = input.nextLong();
System.out.print ("Enter Annual Population Growth Rate: ");
growthRate = input.nextInt();
annualPopIncrease = (growthRate / 100) * currentPop;
estimatedPop = currentPop + annualPopIncrease;

System.out.println ();

System.out.println("Estimated population after one year:     " + estimatedPop);
System.out.println("Estimated population after two years:    " + estimatedPop + (annualPopIncrease * 2));
System.out.println("Estimated population after three years:  " + estimatedPop + (annualPopIncrease * 3));
System.out.println("Estimated population after four years:   " + estimatedPop + (annualPopIncrease * 4));
System.out.println("Estimated population after five years:   " + estimatedPop + (annualPopIncrease * 5));

}
}
```

1. not working broda

1. Thanks for pointing it out. It had input mismatch but it's been corrected and now works fine.

2. The workig data estimated pop * number of years is wron i Think as estimatedpop becomes after one year but multiplying estimatedpop by 2 for the population after two years is mathematical problem which staes that growth rate was 200%. Instead it should be estimatedpop + growth/100 * estimated pop to be precise but if it was just a simple calculation you need to multiply the annualpopincrease by 2 and add it to estimatedpop.

I do not mean to be rude and also THANKS A LOT FOR PROVIDING THE SOLUTIONS IT IS HELPING ME A LOT.

1. Thank you so so much for the correction. Didn't think of it that way - logic error! It has been corrected.

3. I tried double for currentPop but in Eclipse Neon.3 it tells me that value over 7 billion is out of range. Why?

1. I'm not sure. It is supposed to work. Check your value very well. Maybe you typed extra digits.

4. I had to change input.nextLong() to input.nextDouble() and worked well. Otherwise thanks again

DISCLAIMER: Opinions expressed in comments are those of the comment writers alone and does not reflect or represent the views of the post author. We reserve the right to delete any post deemed inappropriate or offensive and/or spammy. Please do not use abusive words/hate speech.

I Appreciate your valuable Feedback. So, Please DO NOT SPAM - Spam comments will be deleted immediately.

Don't use brand name in name field and you're not allowed to use links in comments unless it's necessary. Such comments will be removed immediately. To get notified of replies or follow-up comments, click the box next to notify me.

Thanks.