Hi, im having trouble with a code, it doesnt do what its supposed, theres something wrong with it but i cant find what, maybe you could help me find the problem and fix it.

heres the code:

public static byte[] runlengthencoding(byte[] m) {


byte[] copia = new byte[m.length+9999999];
for(int w = 0; w< copia.length; w++){


copia[w] = (byte)99999; }


for(int y = 0; y< 1077; y++){


copia[y] = m[y]; }
copia[30]=(byte)1;



int contadorperez=1078;
int j=0;
int cont=0;
while (j< m.length-1) {


if (m[j]==m[j+1]){
int repeticion=0;
int h=j+1;
while((h< m.length)&&m[j]==m[h]&&(repeticion<256)){
repeticion++;
h++;
}
copia[contadorperez]=m[j];
copia[contadorperez+1]=(byte)repeticion;
if (1<repeticion){
contadorperez++;
}else{  contadorperez=contadorperez+2;}
j=j+repeticion;
repeticion=0;
h=0;
}
else{
copia[contadorperez]=m[j];
contadorperez++;
j++;
}
}


int p=58;
while (!(copia[p]==(byte)99999&&copia[p+1]==(byte)99999&&copia[p+2]==(byte)99999&&copia[p+3]==(byte)99999&&copia[p+4]==(byte)99999&&copia[p+5]==(byte)99999)){
p++;
}
byte[] feenal = new byte[p];
int r=0;
while(r<feenal.length){
feenal[r]=copia[r];
r++;


}


return feenal;



}

thank you, Pablo

Please edit the post and add code tags around the code. Also, what is it doing that is incorrect? It helps to have some idea of the problem instead of examining every line looking for any trace of a potential error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.