Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since it includes another prime factor 7.
Note that 1 is typically treated as an ugly number.
用num来% 2 3 5 如果为0 那么num就除以多少,最后为1 说明没有其他factors
代码:
public boolean isUgly(int num) {
if (num <= 0) {
return false;
}
int[] divi = {2, 3, 5};
for(int d : divi) {
while (num % d == 0) {
num /= d;
}
}
return num == 1;
}