Given the list of 5 countries and their respective currencies into two
arrays. Develop a program to accept the name of a country as
argument and print the corresponding currency as output.
The program should give an error message when a country’s name
is not in the list. [15]
Given:
Country [ ] = {“India”,”China”, “UAE”, “Japan”, “Britain”};
Currency [ ] = {“Rupee”, “Yaan”, “Dirham”, “Yen”, “Pounds”};
Input : Japan
Output : Yen
Answers
Answer:
Given the list of 5 countries and their respective currencies into two
arrays. Develop a program to accept the name of a country as
argument and print the corresponding currency as output.
The program should give an error message when a country’s name
is not in the list. [15]
Given:
Country [ ] = {“India”,”China”, “UAE”, “Japan”, “Britain”};
Currency [ ] = {“Rupee”, “Yaan”, “Dirham”, “Yen”, “Pounds”};
Input : Japan
Output : Yen
Answer:
class country
{
public void accept(String s)
{
String country[]={"India","China","UAE","Japan","Britain"};
int l=country.length;
String currency[]={"ruppes","yaan","Dirham","yen","Pound"};
int i,flag=0;
for(i=0;i<l;i++)
{
if(s.equalsIgnoreCase(country[i]))
{
flag++;
break;
}
}
if(flag==1)
System.out.println(country[i]+"\t\t"+currency[i]);
else
System.out.println("country not present");
}
}