turing Machine program in java for equal no of 1's and 0's

import java.io.*;
import java.lang.*;
class turing_machine
{
public static void main(String args[])throws IOException
{
int i,n1,n,j,z,count=0,count1=0,turing_machine1;
DataInputStream in=new DataInputStream(System.in);
System.out.println("Enter Input to turing machine");
String s;
s=in.readLine();
turing_machine1=s.length();
char a[]=s.toCharArray();
System.out.print("String->");
for(i=0;i<turing_machine1;i++)
{
System.out.print("\t"+a[i]);
}
System.out.println();
for(i=0;i<turing_machine1;i++)
{
if(a[i]=='0')
{
a[i]='X';
i=(n/2);

}
if(a[i]=='1')
{
a[i]='Y';
i=0;
System.out.print("String->");
for(z=0;z<turing_machine1;z++)
{
System.out.print("\t"+a[z]);
}
System.out.println();
}
}
for(i=0;i<n;i++)
{
if(a[i]=='X'){
count++;}
if(a[i]=='Y'){
count1++;}
}
if(count==count1)
System.out.print("String accepted");
else
System.out.print("String not accepted");
}
}
/*

OUTPUT of turing Machine program in java :

Enter input to turing machine

000111

String-> 0 0 0 1 1 1
String-> X 0 0 Y 1 1
String-> X X 0 Y Y 1
String-> X X X Y Y Y
String accepted
*/

Facing difficulties in understanding the program ?

Ask Your Queries in Comment Box

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *