DFA that begins with ' a ' but does not contain substring ' aab ' | Java code for the above DFA ; Function for state A transition ; If at index 0 ' a ' if found then call stateB function with passing n [ 1 : ] to it ; If at index 0 ' b ' if found then call stateQ function with passing n to it ; Function for transition state B ; length ( ) of String become 0 then print Accepted ; If at index 0 ' a ' if found then call stateC function with passing n [ 1 : ] to it ; If at index 0 ' b ' if found then call stateD function with passing n [ 1 : ] to it ; Function for transition state C ; length ( ) of String become 0 then print Accepted ; If at index 0 ' a ' if found then call stateC function with passing n [ 1 : ] to it ; If at index 0 ' b ' if found then call stateQ function with passing n to it ; Function for transition state D ; length ( ) of String become 0 then print Accepted ; If at index 0 ' a ' if found then call stateC function with passing n [ 1 : ] to it ; If at index 0 ' b ' if found then call stateQ function with passing n to it ; Function for state Q transition ; In dead state it shows String not accepted ; Driver code ; Take String input ; Call stateA to check the input
import java . util . * ; class GFG { static void stateA ( String n ) { if ( n . charAt ( 0 ) == ' a ' ) { stateB ( n . substring ( 1 ) ) ; } else { stateQ ( n ) ; } } static void stateB ( String n ) { if ( n . length ( ) == 0 ) { System . out . print ( " Accepted " ) ; } else { if ( n . charAt ( 0 ) == ' a ' ) stateC ( n . substring ( 1 ) ) ; else stateD ( n . substring ( 1 ) ) ; } } static void stateC ( String n ) { if ( n . length ( ) == 0 ) System . out . print ( " Accepted " ) ; else { if ( n . charAt ( 0 ) == ' a ' ) stateC ( n . substring ( 1 ) ) ; else stateQ ( n ) ; } } static void stateD ( String n ) { if ( n . length ( ) == 0 ) System . out . print ( " Accepted " ) ; else { if ( n . charAt ( 0 ) == ' a ' ) { stateB ( n . substring ( 1 ) ) ; } else { stateD ( n . substring ( 1 ) ) ; } } } static void stateQ ( String n ) { System . out . print ( " Not ▁ Accepted " ) ; } public static void main ( String [ ] args ) { String n = " aaaba " ; stateA ( n ) ; } }