Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help I have the code written out just need help with the ** FOR** how do I correct my error? Assume that the population

Need help I have the code written out just need help with the **FOR** how do I correct my error?

Assume that the population of Mexico is 121 million and that the population increases 1.05% annually (new population = current population x 1.0105).

Assume that the population of the United States is 315 million and that the population is reduced 0.16% annually (new population = current population x 0.9984).

Assume that the population of Japan is 127 million and that the population increases 1.01% annually (new population = current population x 1.0101).

Write an application that displays the populations for the three countries every year until both Mexican and Japanese populations pass US population.

Display the number of years it took for Mexicos and Japans populations to exceed that of the United States. Use both while loop and for loop to accomplish the task. Save the two files (one for each type of loop) as Population_while.java and Population_for.java

My code below:

//US, Japan, and Mexico population every year until Mexico and Japan's population exceeds US population

class Population_for { public static void main(String args[]) { //Initial population of US and Mexico long mexicoPopulation = 1210000000L; long USPopulation = 3150000000L; long JapanPopulation = 127000000L; //Initializing year to 0 int year=2000; //Mexicos and Japans populations to exceed that of the US do { //year count year++; //Mexico Population by 1.05 percent annually mexicoPopulation = mexicoPopulation + (long) ( (mexicoPopulation * 1.05) / 100 ); //US population by 0.16 percent annually USPopulation = USPopulation - (long) ( (mexicoPopulation * 0.16) / 100 ); //Japan population by 1.01 percent annually JapanPopulation = JapanPopulation + (long) ( (mexicoPopulation * 1.01) / 100); //Printing Population year wise System.out.println(" Year: " + year + "\t Mexico: " + (mexicoPopulation / 10000000) + " million \t US: " + (USPopulation / 10000000) + " million \t Japan: " + (JapanPopulation / 10000000) ); }for(mexicoPopulation + JapanPopulation

My Error

image text in transcribed

Tht year=2000, //Mexico's and Japan's populations to exceed that of the US do //year count year++; 1/Mexico Population by 1.05 percent annually mexicoPopulation = mexicoPopulation + (long) ( (mexicoPopulation * 1.05) / 100); //US population by 0.16 percent annually USPopulation = USPopulation - (long) ( (mexicoPopulation * 0.16) / 100); //Japan population by 1.01 percent annually Japan Population - JapanPopulation + (long) ( (mexicoPopulation * 1.01) / 100); //Printing Population year wise System.out.println(" Year: " + year + "\t Mexico: " + (mexicoPopulation / 10000000) + " million \t US: " + (USPopulation / 10 }for (mexicoPopulation + JapanPopulation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Find the derivative. f(x) 8 3 4 mix X O 4 x32 4 x32 3 -4x - x2

Answered: 1 week ago