How to check if an integer can be divided by 3

advertisements

How to check if my integer can be divided by 3 as below:

for(int i=0; i<24;  i++){
   //here, how to check if "i" can be divided by 3 completely(e.g. 3, 6, 15)?

}


Use the modulo operator.

if(i % 3 == 0)

Also see Modulo operation at Wikipedia