0

I don't understand what the % do?

11th Aug 2016, 11:29 AM
monky
monky - avatar
4 Answers
+ 4
% is a modulus operator, and it is used to return the remainder of a division. For example: 5 % 2 = 1 10 % 5 = 0 30 % 7 = 2 A very common, and beginner way to use the modulus is to tell whether or not a number is even: if (x % 2 == 0) { //even } else { //odd }
11th Aug 2016, 12:29 PM
Cohen Creber
Cohen Creber - avatar
+ 1
25:3=8 rest 1 explication: 25/3=8 25%3=1
2nd Sep 2016, 5:58 AM
kiky
0
it returns the remainder
11th Aug 2016, 3:35 PM
PRANJAL AGNIHOTRI
PRANJAL AGNIHOTRI - avatar
0
Yeah, all it does is to return the remainder.
11th Aug 2016, 3:51 PM
Ayobama
Ayobama - avatar