Phone Number List. This program should have an array of at least 10 string objec
ID: 3763295 • Letter: P
Question
Phone Number List. This program should have an array of at least 10 string objects. The array will hold people’s names and phone numbers. The following list is an example of the data in the array.
"Renee Javens, 678-1223",
"Joe Looney, 586-0097",
"Geri Palmer, 223-8787",
"Lynn Presnell, 887-1212",
"Bill Wolfe, 223-8878",
"Sam Wiggins, 486-0998",
"Bob Kain, 586-8712",
"Tim Haynes, 586-7676",
"John Johnson, 223-9037",
"Jean James, 678-4939",
"Ron Palmer, 486-2783"
The program should ask the user to enter a name or partial name to search for in the array. Any entries in the array that match the string entered should be displayed. For example, if the user enters “Palmer” the program should display the following names from the list:
Geri Palmer, 223-8787
Ron Palmer, 486-2783
NOTE: if the user enters “Pal” it should produce the same output.
please do not use classes on the answer.
Explanation / Answer
import java.util.Scanner;
/**
* @author Srinivas
*
*/
public class PhoneNumberList {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String phoneNumberList[] = { "Renee Javens, 678-1223",
"Joe Looney, 586-0097", "Geri Palmer, 223-8787",
"Lynn Presnell, 887-1212", "Bill Wolfe, 223-8878",
"Sam Wiggins, 486-0998", "Bob Kain, 586-8712",
"Tim Haynes, 586-7676", "John Johnson, 223-9037",
"Jean James, 678-4939", "Ron Palmer, 486-2783" };
System.out.print("Enter a name or partial name :");
Scanner scanner = new Scanner(System.in);
String searchName = scanner.nextLine();
for (int i = 0; i < phoneNumberList.length; i++) {
if (phoneNumberList[i].contains(searchName)) {
System.out.println(phoneNumberList[i]);
}
}
}
}
OUTPUT1:
Enter a name or partial name :Palmer
Geri Palmer, 223-8787
Ron Palmer, 486-2783
OUTPUT2:
Enter a name or partial name :Pal
Geri Palmer, 223-8787
Ron Palmer, 486-2783