09A-2016 – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-ICSE2016-09A #JAVA#7334    siteicon   siteicon  

Problem Statement - 09A-2016

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!");
 }

 }
 }

Sample Output

Enter country: INDIA
INDIA – TAJMAHAL


Share

CSKC| Created: 16-Apr-2019 | Updated: 16-Apr-2019|ICSE2016









Back