Sunday, 17 March 2013

Program of BitStuffing


//Inserting a zero(0) after a series of five consecutive one's(1)

import java.util.*;
class BitStuffing
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int []arr=new int[20];
int cnt=0;
System.out.print("Enter string length: ");

int a=input.nextInt();
System.out .print("Enter a string: ");

for(int i=0;i<a;i++)
{
arr[i]=input.nextInt();
}
for(int i=0;i<a;i++)
{
if(arr[i]==1)
cnt++;
else
cnt=0;

if(cnt==5)
{
arr[i]=10;
cnt=0;
}
}

System.out.println("Your String is:");
for(int i=0;i<a;i++)
{
System.out.print(arr[i]);
}


}
}

1 comment: