samedi 28 novembre 2020

why can't my java code read the condition?

first of all, sorry for bad english. I'm a university student studying computer science.

what I attend to do is when the array(from 0 to n-1) is given, to sum the array values with the index minus multiple of 3 start from the end. for example, when 7 arrays are given, I want to sum a[0] a[2] a[3] a[5] a[6].

below is error part of the code I programmed.

        int j = 0;

        for(int i=0; i<n; i++){
                j = i*3;

                if(i!=n-j)
                        r += array[i];
        }

my code can't read the condition and just sum all the array values. I don't know why. can someone help me ?

Aucun commentaire:

Enregistrer un commentaire