lundi 27 juin 2016

Please Explain This Java Code

I'm a newbie to Java, and I've been asked to consider what types of test cases could be developed for the code below. Could someone go over a.length. a[index] == 'A', and int index = 0,i =0, j =0, k = 0,b = 0 in particular because I don't understand these at the moment. Thanks!

public class Over {
int count(char[] a)
{
    int index = 0,i =0, j =0, k = 0,b = 0;
    if(a[index] == 'A')
    {
        b=1;


    for(index=b;index<a.length;index++)
    {            


        if(a[index] == 'B')
        {
            j = j+1;
            k = 0;

        }


        if(a[index] == 'C')
        {
            i = i + j;
            k = k + 1;
            j = 0;

        }

        }


    }
    else
        {
            i = -1;
        }
    return i;
}

}

Aucun commentaire:

Enregistrer un commentaire