Write a program to initialize the seven Wonders of the World along with their locations in two different arrays. Search for a 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!” [15]
Seven wonders – CHICHEN ITZA, CHRIST THE RDEEEMER, 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!
Solution
TC++ #7334
import java.util.Scanner;
public class SevenWonders {
public static void main(String[] args) {
String[] sevenWonders = { "CHICHEN ITZA", "CHRIST THE RDEEEMER", "TAJMAHAL", "GREAT WALL OF CHINA",
"MACHU PICCHU", "PETRA", "COLOSSEUM" };
String[] locations = { "MEXICO", "BRAZIL", "INDIA", "CHINA", "PERU", "JORDAN", "ITALY" };
Scanner scanner = new Scanner(System.in);
System.out.print("Enter country: ");
String country = scanner.next();
// Search country in the array using linear search
int index = -1;
for (int i = 0; i < locations.length; i++) {
if (locations[i].equals(country)) {
index = i;
}
}
if (index != -1) {
System.out.println(locations[index] + " - " + sevenWonders[index]);
} else {
System.out.println("Sorry Not Found!");
}
}
}