// Linear or sequential search

import javax.swing.JOptionPane;

public class Search1819
{ String[] names = new String[17];
public Search1819()
{ names[0] = "Pratyush"; names[1] = "Tanuj";
names[2] = "James"; names[3] = "Isaac";
names[4] = "Jake"; names[5] = "Ricard";
names[6] = "Sophie"; names[7] = "Amna";
names[8] = "Jocelyn"; names[9] = "Jodie";
names[10] = "Terence"; names[11] = "Romir";
names[12] = "Andrew"; names[13] = "Harris";
names[14] = "Bridget"; names[15] = "Dylan";
names[16] = "Sameet";
}

// Is 'name' in the list?
public boolean linearSearch(String name)
{ boolean foundIt = false;
for (int k = 0; k < names.length; k++)
{     String nameInList = names[k];
    if (name.equalsIgnoreCase(nameInList))
    {     foundIt = true;
    return foundIt;
}
}
return foundIt;
}

public static void main(String[] args)
{ Search1819 s = new Search1819();
String toFind = JOptionPane.showInputDialog("Name? ");
boolean found = s.linearSearch(toFind);
String msg = "Was " + toFind + " found? ";
JOptionPane.showMessageDialog(null, msg + found); } }