C
C
Chvalov2015-09-14 11:52:15
Java
Chvalov, 2015-09-14 11:52:15

How can I skip multiple elements from the array in my case?

There is an array:

public static float MassCurrentsPhases[] = new float[27];

    private static float calculatePhase(int i, float[] MassCurrentsPhases) {
        return MassCurrentsPhases[0 + i] + MassCurrentsPhases[3 + i] + MassCurrentsPhases[6 + i] + MassCurrentsPhases[9 + i] + MassCurrentsPhases[12 + i]
                + MassCurrentsPhases[15 + i] +MassCurrentsPhases[18 + i] + MassCurrentsPhases[21 + i] + MassCurrentsPhases[24 + i];
    }
int i takes the value 0, 1, 2
how can I make it so that if the value of int b = 8 then MassCurrentsPhases[24 + i] is written 0 ?
if b = 7 then the value of MassCurrentsPhases[21 + i] was written 0 ?
The value b * 3 after which in the array the next 3 values ​​are written with zeros
How to do this ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Moseychuk, 2015-09-14
@fshp

for(int i = b*3; i < b*3+3; ++i) {
    data[i] = 0;
}

Something like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question