What is the index of the first character in a string?
0
Updating the current character is done as follows:
public boolean recognize(String str)
{
final int reject = 3;
int state = 0;
char current;
int index = 0
while ( ... )
{
current = str.charAt( index++ );
. . . . .
}
Recall that index++ adds one to index after
using it.
It is good practice to get the current character at just one place in the code, usually at the top of a loop. This makes the translation from automaton to code easier, and makes the code more readable.
Now we need to deal with:
while ( ... )
Either one of two conditions will stop the automaton. What are those conditions? (You may wish to look at the diagram of the finite automaton ).