ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2012 ICSE Computer Science Paper



Share with a Friend

Solved 2012 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

STD (Subscriber Trunk Dialing) Codes Program - ICSE 2012 Computer Science

Write a program to accept the names of 10 cities in a single dimension array and their STD (Subscriber Trunk Dialing) codes in another single dimension integer array. Search for a name of a city input by the user in the list. If found, display “Search successful” and print the name of the city along with its STD code, or else display the message “Search unsuccessful, no such city in the list”.

import java.util.Scanner; class STDSearch{ public static void main(String args[]){ Scanner in = new Scanner(System.in); String c[] = new String[10]; int s[] = new int[10]; int i; for(i = 0; i < c.length; i++){ System.out.print("City: "); c[i] = in.nextLine(); System.out.print("STD Code: "); s[i] = Integer.parseInt(in.nextLine()); } System.out.print("City name to be searched: "); String key = in.nextLine(); i = 0; while(i < c.length){ if(key.equalsIgnoreCase(c[i])) break; i++; } if(i == c.length) System.out.println("Search unsuccessful. No such city in the list"); else{ System.out.println("Search successful"); System.out.println(c[i] + " - " + s[i]); } } }

Output

 
 OUTPUT : 
 
City: New Delhi
STD Code: 011
City: Mumbai
STD Code: 022
City: Kolkata
STD Code: 033
City: Chennai
STD Code: 044
City: Bangalore
STD Code: 080
City: Lucknow
STD Code: 0522
City: Bhubaneswar
STD Code: 0674
City: Indore
STD Code: 0731
City: Pune
STD Code: 020
City: Agra
STD Code: 0562
City name to be searched: Chennai
Search successful
Chennai - 44