-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonSearch.java
More file actions
35 lines (27 loc) · 975 Bytes
/
PersonSearch.java
File metadata and controls
35 lines (27 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* This program demonstrate the startsWith method
* to search a partial string.
*/
import java.util.Scanner;
public class PersonSearch
{
public static void main (String [] args)
{
String lookUp;
String [] people = {"Angie", "Karol", "Ana",
"David", "Edwin", "Mike",
"Will", "Rose", "Oscar",
"Albert", "Mario", "Link",
"Zelda", "Samayoa, Karol"};
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the first few characters of " +
"the last name of the look up: ");
lookUp = keyboard.nextLine();
System.out.println("Here are the names that match:");
for (String person : people)
{
if (person.startsWith(lookUp))
System.out.println(person);
}
}
}