判断2个数是否能被除尽java(可以小数)

来源:互联网 发布:苍之骑士团台服数据库 编辑:程序博客网 时间:2024/05/01 19:12
 /**
  * 
  * @param amount 除数
  * @param count 被除数
  * @return
  */
 public static boolean check(int amount,int count){
if(amount%count==0){
return true;// 能被除尽
}
else{

int m=count;
while(m%2==0){
m=m/2;// 当模2不=0时,去尝试对5取模
}
while(m%5==0){
m=m/5;// 当模5不=0时,则将m让除数取模
}
if(amount%m!=0){
return false;// 不能除尽,如果取模不为0,则表示有2和5以外的因子,数学原理也是别人告诉我的:除数能被分解成N个2或N个5或者N2N5组合,则表示可以除尽
}
}
 
return true;
 }
 
0 0
原创粉丝点击