Kevin321888999

Java: Mexico Population VS United States Population

Oct 27th, 2022 (edited)
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. //This program calculates the population of both the US and Mexico. It stops when the Mexican population reaches half of the amount of the US Population.
  2. class Mexico_andUS_POP {
  3.     public static void main(String[] args){
  4.         Banner();
  5.         int years=0;
  6.         int mexico_population=130000000;
  7.        //counter for counting hte number of years.
  8.         int US_population=332000000;
  9.  
  10.        while(mexico_population<(US_population * 0.5)){
  11.            mexico_population = (int) (mexico_population *1.0137);
  12.            US_population =  (int) (US_population * 1.006);
  13.            years+=1;
  14.        }
  15.        System.out.println("The population of Mexico will be half of the population of the US in: "+years+ " years");
  16.     }
  17.     public static void Banner(){
  18.         System.out.println("Malachi Sor CS151 Homework 3");
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment