California has a population of 39 million and is declining by 3% per year. Texas has a population of 29 million and is increasing by 1% per year. How many years will it be until TX has more people that CA? Write a program in Java that answers this question.
public class Main
{
public static void main(String[] args) {
int pop_CA=39000000; //population
of california
int pop_TX=29000000; //population
of texas
int yr=0;
while(pop_CA>pop_TX){
pop_CA=pop_CA-3/100*pop_CA;
//decrease by 3%
pop_TX=pop_TX+pop_TX/100;
//decrease by 1%
yr+=1;
}
System.out.println(yr);
}
}
OUTPUT:-
Get Answers For Free
Most questions answered within 1 hours.