Hi, I've got a project in which I need the program to reject a sentence if it has a certain word in it using StringTokenizer. Here is what I have so far
import TerminalIO.*;
import java.util.*;
public class Censor
{
public static void main(String args[])
{
KeyboardReader reader = new KeyboardReader();
System.out.println("Enter next sentence: ");
String s = reader.readLine();
StringTokenizer stk = new StringTokenizer(s);
String ac = ">>>ACCEPTED";
for(int j = 0; j < stk.countTokens();j++)
{
String nxt = s.nextToken();
if(nxt.equalsIgnoreCase("hermes"))
ac = ">>>REJECTED";
else if(nxt.equalsIgnoreCase("bridge"))
ac = ">>>REJECTED";
else if(nxt.equalsIgnoreCase("Muddy"))
ac = ">>>REJECTED";
else if(nxt.equalsIgnoreCase("River"))
ac = ">>>REJECTED";
else if(nxt.equalsIgnoreCase("assault"))
ac = ">>>REJECTED";
else if(nxt.equalsIgnoreCase("offensive"))
ac = ">>>REJECTED";
}
System.out.println(s + ac);
}
}
it doesn't exactly work so any help is appreciated.