samedi 3 janvier 2015

Aray of Char[ ] , find some letter in an aray


Vote count:

0




I have to do a method that finds if an array of char[ ] like {'d','e','f' } is inside of an other array of char[ ] like {'a','b','c','d','e','f','x','r'} ... So , i want that my "x" inside while cicle raises when a letter is found . For example , when my for cycle finds the 1st letter my x= 1 , if for cycle finds the 2nd letter my x = x+1 and so on ... So my x should be equal to the length of the array {'d','e','f'} . Whereas if i have to find an array like {'d','e','f'} in an other array like {'a','d','z','x'} my x is 1 so it is not equal to the length of the array {'d','e','f'}, There is something wrong but I can't find the mistake . Thanks



public int find2(char[]subs)
{
int x = 1 ;
for(int i=0 ; i<this.lunghezza(); i++ )
{
if(this.array1[i] == subs[0])
{
for ( int k = 1 ; k< subs.length ; k++)
{
while (this.array1[i+k]== subs[k])
{
x = x+1; ;
}
}
}
}
return x;
}


asked 54 secs ago







Aray of Char[ ] , find some letter in an aray

Aucun commentaire:

Enregistrer un commentaire