Answer:
import java.util.Scanner;
public class ContactInformation
{
public static String GetPhoneNumber(String[] nameVec, String[] phoneNumberVec, String contactName, int arraySize)
{
for(int i=0;i<arraySize;i++)
{
if(nameVec[i].equals(contactName))
return phoneNumberVec[i];
}
return "Contact doesn't exists!";
}
public static void main(String[] args)
{
int records;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the size of contact List :");
records=sc.nextInt();
String[] contactNameList=new String[records];
String[] phoneNumberList=new String[records];
String contactName;
System.out.println("Enter the contact name and phone number :");
for(int i=0;i<contactNameList.length;i++)
{
contactNameList[i]=sc.next();
phoneNumberList[i]=sc.next();
}
System.out.println("Enter the name of the contact to be searched :");
contactName=sc.next();
System.out.println(GetPhoneNumber(contactNameList,phoneNumberList,contactName,records));
}
}
Explanation:
In the following the function defined above for getting the contact
number on the basis of contact number provided we are checking the contact name list if we are able to find the contact name and if we did we return the contact number on the same index from the contact number list
which we found in the contact name list.