It would be nice to let the user enter the String to search for.
Further hacks you might consider would
allow the user to add and delete Strings in the array.
But lets do more than that.
Let us make this program an (almost) practical application.
Our application will search for a name and will
then print out that person's phone number.
The list of names and phone numbers is implemented
as an array of references to PhoneEntry objects:
The phone number is a String (not an int) because no
arithmetic is done with it,
and because it may contain colons and dashes.
class PhoneEntry
{
private String name; // name of a person
private String phone; // their phone number
public PhoneEntry( String n, String p )
{
name = n; phone = p;
}
public String getName() {return name;}
public String getPhone() {return phone;}
}
Are PhoneEntry objects immutable?