the concept of the program is ... if ypu enter the input as 'ABDF' , the output should be 110101 ... for A.B,D,F which is present 1 is replaced .. for the missing c and e , 0 is added ...
the length is assigned as 6 .. so if we enter 'A' , then the output should be 100000 ... but i am getting an arrayoutofbound exception ... can you help me to find the error...
here is the program ..............
class TCheck
{
public static void main(String [] args)
{
int blen = 6;
String aString = "ABC";
int binArray[] = new int[blen];
int c,k=0,asciiVal=65,x=0;
char chArray[] = aString.toCharArray();
for(int i=0;i<chArray.length;i++)
System.out.println(chArray[i]);
for(int i =0;i<blen;i++)
{
if(chArray[x] == asciiVal)
{
binArray[k] = 1;
x++;
}
else
binArray[k] = 0;
k++;
asciiVal++;
}
for(int i=0;i<k;i++)
System.out.println(binArray[i]);
int l =0,tenPower,binaryValue=0,n=k-1;
for(int i=0;i<k;i++)
{
tenPower = (int)Math.pow(10,n);
binaryValue = binaryValue +( binArray[i] * tenPower);
n--;
}
System.out.println("binaryValue --------- "+binaryValue);
}
}