Program to construct a DFA which accepts the language L = { aN | N â ‰¥ 1 } | Java program for the above approach ; Function to check whether the String S satisfy the given DFA or not ; Stores the count of characters ; Iterate over the range [ 0 , N ] ; Count and check every element for ' a ' ; If String matches with DFA ; If not matches ; Driver Code ; Function Call
class GFG { static void isAcceptedDFA ( String s , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( s . charAt ( i ) == ' a ' ) count ++ ; } if ( count == N && count != 0 ) { System . out . print ( " Accepted " ) ; } else { System . out . print ( " Not ▁ Accepted " ) ; } } public static void main ( String [ ] args ) { String S = " aaaaa " ; isAcceptedDFA ( S , S . length ( ) ) ; } }