Ugly Number
2016-06-13 15:42
260 查看
题目描述:
Write a program to check whether a given number is an ugly number.
Ugly numbers are positive numbers whose prime factors only include
Note that
这个题非常简单,直接上代码:
public class Solution {
public boolean isUgly(int num) {
if(num<1)
return false;
while(num!=1){
if(num%2==0){
num/=2;continue;
}
if(num%3==0){
num/=3;continue;
}
if(num%5==0){
num/=5;continue;
}
return false;
}
return true;
}
}
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, 8are ugly while
14is not ugly since it includes another prime factor
7.
Note that
1is typically treated as an ugly number.
这个题非常简单,直接上代码:
public class Solution {
public boolean isUgly(int num) {
if(num<1)
return false;
while(num!=1){
if(num%2==0){
num/=2;continue;
}
if(num%3==0){
num/=3;continue;
}
if(num%5==0){
num/=5;continue;
}
return false;
}
return true;
}
}
相关文章推荐
- python客户端监控工具
- java并发包java.util.concurrent
- 利用pandas读取中文数据集
- linux下打包出现brut.common.BrutException: could not exec command: [/tmp/brut_util_Jar_22418586694498,解决方案
- mysql远程连接10061
- 运算符的重载—分数
- break ,continue, return
- win7(64位)如何修改开机登陆界面
- 使用 Jasmine 进行测试驱动的 JavaScript 开发
- android项目重构之mvp
- android项目重构之mvp
- android项目重构之mvp
- android项目重构之mvp
- android项目重构之mvp
- android项目重构之mvp
- 深入Java集合:LinkedHashMap实现原理
- ImageLoder简单使用
- RxJava操作符(06-错误处理)
- RxJava操作符(06-错误处理)
- 6 SQLite与ContentProvider