Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a hash map of the names of 20 countries in the world. Those are the keys.

ID: 3578467 • Letter: C

Question

Create a hash map of the names of 20 countries in the world. Those are the keys. And the values are the populations of those countries. Then write a program that asks the user to type in the name of a country. And use that as the key to get the population of that country. Create a hash map of the names of 20 countries in the world. Those are the keys. And the values are the populations of those countries. Then write a program that asks the user to type in the name of a country. And use that as the key to get the population of that country.

Explanation / Answer

import java.util.*;
public class HashMap {

public static void main(String args[]) {

HashMap map = new HashMap();
  
map.put("usa", new Double(324118787));
map.put("france", new Double(64668129));
map.put("germany", new Double(80682351));
map.put("italy", new Double(59801004));
map.put("australia", new Double(24309330));
map.put("japan", new Double(126323715));
map.put("mexico", new Double(128632004));
map.put("chile", new Double(18131850));
map.put("brazil", new Double(209567920));
map.put("poland", new Double(38593161));
map.put("england", new Double(65111143));
map.put("ireland", new Double(4713993));
map.put("iceland", new Double(331778));
map.put("norway", new Double(5271958));
map.put("sweden", new Double(9851852));
map.put("austria", new Double(8569633));
map.put("syria", new Double(18563595));
map.put("nigeria", new Double(186987563));
map.put("pakistan", new Double(192826502));
map.put("colombia", new Double(48654392));

Set set = map.entrySet();
  
Iterator i = set.iterator();
  
while(i.hasNext()) {
Map.Entry country = (Map.Entry)i.next();
System.out.print(country.getKey() + ": ");
System.out.println(country.getValue());
}
System.out.println();
  
System.out.println("Enter country name : ");
Scanner input = new Scanner(System.in);
String name = input.nextLine();
System.out.println("Population : " + map.get(name));
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote