Skip to content
Advertisement

Program that stores the names and populations of 12 countries two arrays of the same size

Use data below

Countries: USA, Canada, France, Belgium, Argentina, Luxembourg, Spain, Russia, Brazil, South Africa, Algeria, Ghana

Population in millions: 327, 37, 67, 11, 44, 0.6, 46, 144, 209, 56, 41, 28

Use two arrays that may be used in parallel to store the names of the countries and their populations.

Write a loop that neatly prints each country name and its population.

JavaScript

}

If you notice from the instructions Luxembourg is suppose to be 0.6 but I put 1. Every time I try to make this a double I get an error. Currently im using int but it has to be a double. Any advice I appreciate it. I already tried changing it to double [] but I still get an error. Changed the population size and the loop below from int to double did not work. Error in java

Advertisement

Answer

you need to change the populationSize to array of Double and assign double values use correct format specifier for double, i have used %.2f f is for floating point number, which includes double and 2 says two digits after decimal point

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement