Number of 1’s is not multiple of three. Let L be a language over alphabets {0, 1} such that number of 1’s is multiple of 3.

Thus, L = [ ω ϵ {0, 1}* | no. of 1’s in ω is multiple of 3]

Complement of L is given by :

L’ = [ ω ϵ {0, 1}* | no. of 1’s in ω is not multiple of 3]

DFA for L’ can be obtained through following modification on DFA for L.

- 1. Every final state of L should become a non – accepting state is L’.
- 2. Every non-accepting state of L should become a final state in L’.

**Designing DFA step by step:**

### Step – 1:

Make initial state “q_{0}” then it is the possibility that there would not be any ‘1’ but have only ‘0’ in the string which is acceptable because 1 is not multiple of 3. So, in this case, any number of 0’s can be present here and for this self-loop of ‘0’ on initial state “q_{0}“.

**Step -2:**

Create transition of input alphabet ‘1’ from state “q_{0}” to state “q_{1}“.

**Step -3:**

After one ‘1’ any number of 0’s can be present i.e, no ‘0’ or more than one ‘1’. For this put self-loop ‘0’ on state “q_{1}“.

**Step -4:**

Now create transition of input alphabet ‘1’ from state “q_{1}” to state “q_{2}“.

**Step -5:**

After that two 1’s any number of 0’s can be found in the string and for this put self loop of 1’s on initial state “q_{2}“.

**Step -6:**

Before the transition of the third ‘1’ we need to think about the logic so that after the transition the machine will accept the string the number of ones not multiple of 3. For this transit ‘1’ from the state “q_{2}” to state “q_{0}“. As third one is reach to state “q_{0}” so make state “q_{1}” and “q_{2}” be final state.

Transition table of above DFA:

**Code:**

**Main.java**

package com.company.finite_automata; import java.util.Scanner; public class DFA_1_multiple_3 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the String"); String str = sc.nextLine(); checkStateA(str); } private static void checkStateA(String str) { if (str.length() == 0){ System.out.println("string not accepted"); } else { if(str.charAt(0)=='0') checkStateA(str.substring(1)); else stateB(str.substring(1)); } } private static void stateB(String str) { if(str.length() == 0){ System.out.println("String Accepted"); } else { if(str.charAt(0)=='0') stateB(str.substring(1)); else stateC(str.substring(1)); } } private static void stateC(String str) { if(str.length() == 0){ System.out.println("String Accepted"); } else { if(str.charAt(0)=='0') stateC(str.substring(1)); else checkStateA(str.substring(1)); } } }

**Output:**

Enter the String 10101 string not accepted

**Recommended:**

- Introduction to Finite Automata
- Deterministic Finite Automata (DFA)
- Number of 1’s is a multiple of 3 on {0,1} using DFA
- Automata Theory and Formal Languages
- Kleene Closure
- Recursive Definition of a Language
- Finite Representation of language
- Introduction to Finite Automata
- Deterministic Finite Automata (DFA)