johndoe3344
Programmer
How would I test whether a number is divisible by a certain combination of numbers (say 2 and 3?)
The number 4 fits, because it divides by 2, and then by 2.
The number 12 fits, because it divides by 3, then by 2 twice.
The number 15 doesn't fit because after dividing by 3, 5 is not divisible by 2 or 3 any further.
I would imagine the method has something to do with the modulus operator, but I can only see how to use the modulus operator to check if a number x is divisble by a number y.
if (x % y == 0) {
...}
Could anyone shed some light on this? Thanks.
The number 4 fits, because it divides by 2, and then by 2.
The number 12 fits, because it divides by 3, then by 2 twice.
The number 15 doesn't fit because after dividing by 3, 5 is not divisible by 2 or 3 any further.
I would imagine the method has something to do with the modulus operator, but I can only see how to use the modulus operator to check if a number x is divisble by a number y.
if (x % y == 0) {
...}
Could anyone shed some light on this? Thanks.