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)); } }

Click here to see other answers to Java How to Program.

not working broda

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

DeleteThe 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.

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

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

DeleteP.S. I'm glad you find it helpful.

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

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

Delete