I have a question for one of my high school programming projects and i'm not really sure where to start. Here's the problem.
"Mexico's population is 62 million and is growing at the annual rate of 7%. The United States' current population is 280 million and is growing at the annual rate of 2%. If these two countries were to maintain their current rates of growth, in how many years will Mexico's population be more than half that of the United States? Your program should answer this question."
I decided to make it so it would run Mexico's population * 1.07^years and USA's pop * 1.02^years
but when I run my program it says that Mexico's pop. catches up to half of the USA's in 1 year which is definitely not true. (the answer is 18 years)
Any help is appreciated!
import java.util.Scanner; public class h3q3 { public static void main (String [] args){ Scanner scan = new Scanner (System.in); double mex = 62000000; double usa = 280000000; double years = 0; while(mex <= usa/2) { years++; mex = mex * Math.pow(1.07, years); usa = usa * Math.pow(1.02, years); if (mex > (usa/2));{ break; } } System.out.println ("Mexicos population is half of America's in " + years + "years "); } }