Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
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!
Answer:
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!");
}
}
}
Sample Output
Enter country: INDIA
INDIA – TAJMAHAL
C. Sir| Created: 16-Apr-2019 | Updated: 16-Apr-2019|ICSE2016