Advertisements
Advertisements
Question
Write a program to initialize the seven Wonders of the World along with their locations in two different arrays. Search for the name of the country input by the user. If found, display the name of the country along with its Wonder, otherwise display “Sorry Not Found!”.
Seven wonders — CHICHEN ITZA, CHRIST THE REDEEMER, TAJMAHAL, GREAT WALL OF CHINA, MACHU PICCHU, PETRA, COLOSSEUM
Locations — MEXICO, BRAZIL, INDIA, CHINA, PERU, JORDAN, ITALY
Example —
Country Name: INDIA Output: INDIA-TAJMAHAL
Country Name: USA Output: Sorry Not Found!
Advertisements
Solution
import java.util.Scanner;
class test
{
public static void main()
{
String w [] = {"Chichen Itza", "Christ The Redeemer", "Taj Mahal", "Great wall of china", "Machu Picchu"; "Petra Colosseum"};
String L [] = {"Mexico, "Brazil", "India", "China", "Peru", Jordan", "Italy"};
Scanner sc = new Scanner (System.in);
System.out.println ("Enter country Name");
String c = sc.next();
boolean found = false;
for (int i = 0; i<w.length(); i++)
{
if (L [i].equalsIgnoreCase(c))
{
found = true;
System.out.println (L[i] + "-" + w[i]);
break;
}
}
if(found = = false)
System.out.println ("Sorry Not found");
}
}
APPEARS IN
RELATED QUESTIONS
Write the return data type of the following function:
endsWith( )
Define a class to accept a string, convert it into lowercase and check whether the string is a palindrome or not.
A palindrome is a word that reads the same backward as forward.
Example:
madam, racecar etc.
The String class method to join two strings is ______.
The output of the function "COMPOSITION". substring(3, 6):
Give the output of the following String class method:
"COMMENCEMENT".lastIndexOf('M')Define a class to accept a String and print the number of digits, alphabets and special characters in the string.
| Example: | S = "KAPILDEV@83" |
| Output: | Number of digits - 2 ' Number of Alphabets - 8 Number of Special characters - 1 |
int x = 98; char ch = (char)x; what is the value in ch?
The output of the statement "CONCENTRATION" indexOf('T') is ______.
The output of the statement "talent". compareTo("genius") is ______.
Write the output of the following String methods:
String x="Galaxy",y="Games";
(a) System.out.println(x.charAt(0)==y.charAt(0));
(b) System.out.println(x.compareTo(y));