+ 1
how to write a program using arrays to store the names & phone no.s of 75 people & to print no. Of of any name entered?
2 Answers
+ 2
save that data to a file.
on running the program, input and save all that data to an array
create a search function that walks the array and uses
userInput.equals(array[x][0]);
//written as this assuming it has a 0 and 1 index for name and number.
until it finds a match. if its a match print it and either look for more or stop the search.
+ 1
//Create a Map
Map<String, String> contacts = new HashMap<String, String>();
//Add Contacts
contacts.put("John", "8675309");
contacts.put("Sally", "9001234567");
contacts.put("Emergency", "911");
//Get number with a variable
String getNum = contacts.get("John");
System.out.println(getNum);
//Print number direct
System.out.println(contacts.get("Sally"));
//Enter a name with input
Scanner scan = new Scanner(System.in);
String another = scan.nextLine();
System.out.println(contacts.get(another));