I
I
Ivan Balaksha2014-01-29 17:16:49
Android
Ivan Balaksha, 2014-01-29 17:16:49

How does the % operator work in android

I studied a little Java, there% is the remainder of the division.
Now I'm reading a book on Android, and there is such an entry
int mCurrentIndex
...
mQuestionBank[]
...
mCurrentIndex = (mCurrentIndex + 1) % mQuestionBank.length;
...
How does it work here?
Yandex did not help with the answer
Here is the code on pastebin
pastebin.com/WuqsFYHQ

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Peretyatko, 2014-01-29
@tagantroy

and it works, returns the remainder of the division;
suppose mQuestionBank.length = 5, then the remainder of dividing by 5 will be from 0 to 4.
this means that with successive calls to this line, mCurrentIndex will be assigned a value one more than the previous one, and when the value reaches 5, after receiving the remainder of the division, it will again become zero

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question