The following code is part of a searchengine
the specific piece of code sorts out the different searching options.
While running it i get the catch (Exception e) error
import java.util.*;
public class ObtainKey
{
public static void KeyAnalyzer()
{
int idx = 0;
int tokenCount;
String input;
String inputArr[] = new String [10];
System.out.println("Enter Search Key :");
Scanner getKey = new Scanner(System.in);
input = getKey.nextLine();
StringTokenizer st = new StringTokenizer(input);
tokenCount = st.countTokens();
while (st.hasMoreTokens())
{
inputArr[idx]=st.nextToken(); idx++;
}
int position = 0;
if (tokenCount == 1)
{
System.out.println("Looking for : " + inputArr[0]);
}
if (tokenCount == 2)
{
System.out.println("Looking for : " + inputArr[0] + " , " + inputArr[1] + "words");
}
try
{
for (position=0; position<inputArr.length; position++)
{
if (inputArr[position].contains("and"))
{
System.out.println("Looking for " + inputArr[position-1] + " and " + inputArr[position+1]);
}
else if (inputArr[position].contains("AND"))
{
System.out.println("Looking for " + inputArr[position-1] + " AND " + inputArr[position+1]);
}
else if (inputArr[position].contains("or"))
{
System.out.println("Looking for " + inputArr[position-1] + " or " + inputArr[position+1]);
}
else if (inputArr[position].contains("OR"))
{
System.out.println("Looking for " + inputArr[position-1] + " OR " + inputArr[position+1]);
}
else if (inputArr[position].contains("\""))
{
System.out.println("Looking for " + inputArr[1] + " And " + inputArr[2] + " words with proximity.");
}
}
}
catch (Exception e)
{
System.err.println("Error: " + e.getMessage());
}
}
}
Any ideas ?