A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Assume that the list will always contain less than 20 word pairs.

Respuesta :

Answer:

/ Contactlist.java

import java.util.Scanner;

public class PhoneContacts

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 "";

   }

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       int n = in.nextInt();

       String[] names = new String[n];

       String[] numbers = new String[n];

       for (int i = 0; i < n; i++) {

           names[i] = in.next();

           numbers[i] = in.next();

       }

       System.out.println(GetPhoneNumber(names, numbers, in.next(), n));

   }

}

In this exercise we have to use the knowledge of computational language in JAVA  to describe the code, like this:

We can find the code in the attached image.

The code can be written more simply as:

/ Contactlist.java

import java.util.Scanner;

public class PhoneContacts

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 "";

  }

  public static void main(String[] args) {

      Scanner in = new Scanner(System.in);

      int n = in.nextInt();

      String[] names = new String[n];

      String[] numbers = new String[n];

      for (int i = 0; i < n; i++) {

          names[i] = in.next();

          numbers[i] = in.next();

      }

      System.out.println(GetPhoneNumber(names, numbers, in.next(), n));

  }

}

See more about JAVA at brainly.com/question/2266606

Ver imagen lhmarianateixeira