Skip to content

Commit a5ee362

Browse files
committed
upload 1 answer, Aug 18th
1 parent 82b2ae9 commit a5ee362

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Diff for: Easy/UglyNumber.java

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Write a program to check whether a given number is an ugly number.
3+
4+
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.
5+
6+
Note that 1 is typically treated as an ugly number
7+
*/
8+
9+
public class UglyNumber {
10+
public boolean isUgly(int num) {
11+
if(num <= 0) return false;
12+
while(num != 1){
13+
if(num %2 == 0) {
14+
num = num /2;
15+
} else if(num % 3== 0) {
16+
num = num /3;
17+
} else if(num % 5 == 0) {
18+
num = num/5;
19+
} else{
20+
return false;
21+
}
22+
}
23+
return true;
24+
}
25+
}
26+
27+
/*
28+
http://blog.csdn.net/nisxiya/article/details/46767595
29+
http://blog.csdn.net/martin_liang/article/details/45692933
30+
http://blog.csdn.net/u010786672/article/details/44259927
31+
*/

0 commit comments

Comments
 (0)