Question: Hello Capitals
You and your friends want to travel the capitals of 10 countries. The problem is, you and your friends are not good at geography. You are asked to write a program that will tell you the capital you want to visit. Here are the list of 10 countries, with their capital city:
Sweden: Stockholm
Australia: Canberra
New Zealand: Wellington
Netherlands: Amsterdam
Canada: Ottawa
Norway: Oslo
Jordan: Amman
Finland: Helsinki
Romania: Bucharest
Columbia: Bogota
Write a method Met that takes as parameter a String and prints the capital of the country.
Only write the method - assume that the Class & main method have been defined.
Use the System.out.println() statement for printing.
Example Input: Sweden
Output: Stockholm
Example Input: Canada
Output: Ottawa
nitish8089:
use Hash map...
Answers
Answered by
0
input:india
output:delhi
output:delhi
Answered by
1
import java.util.HashMap;
import java.util.Scanner;
public class Program
{
public static void met(String state){
HashMap<String, String> state_capital=new <String, String> HashMap();
state_capital.put("Sweden", "Stockholm");
state_capital.put("Australia", "Canberra");
state_capital.put("New zeland","Wellington");
state_capital.put("Canada","Otawa");
state_capital.put("Norway", "Oslo");
state_capital.put("Jordan", "Amman");
state_capital.put("Finland", "Helsiniki");
state_capital.put("Romania","Bucharest");
state_capital.put("coulmbia", "Bogota");
System.out.println(state_capital.get(state));
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String state=sc.next();
Program.met(state);
}
}
Similar questions