End position is checked using the string length value . q0 is the starting state . q1 and q2 are intermediate states . q3 and q4 are final states .
static void q1 ( String s , int i ) { System . out . print ( " q1 - > " ) ; if ( i == s . length ( ) ) { System . out . println ( " NO " ) ; return ; }