當前位置:首頁 » 編程語言 » 最小公倍數java

最小公倍數java

發布時間: 2024-10-16 14:07:26

java編程出三個數中的最小公倍數

你好,這是代碼


LeastCommonMultipleTest.java

{
publicstaticvoidmain(String[]args){
//三個數
inta=7,b=9,c=11;
//最小公倍數
intnumber=0;
//從0開始判斷,無上限(最大可能是三個數字的乘積)
while(!isCommonMultipleNum(number,newint[]{a,b,c})){
//從0開始判斷,不是公倍數就+1
number++;
}
System.out.printf("最小公倍數是:"+number);
}

/**
*判斷某數是否為幾個數字的公倍數
*
*@paramnumber
*要判斷是否為公倍數的數字
*@paramarr
*數字數組
*@return判斷結果,是公倍數返回true,不是返回false
*/
(intnum,int[]arr){
//循環判斷每一個數字
for(inti=0;i<arr.length;i++){
intcurrent=arr[i];
if(num<current||num%current!=0){
returnfalse;
}
}
returntrue;
}
}

❷ 如何用Java求兩個數的最小公倍數

//求最大公約數

publicstaticintcommonDivisor(intn,intm){

//輾轉相除是用大的除以小的。如果nwhile(n%m!=0){

inttemp=n%m;

n=m;

m=temp;

}

returnm;

}

//求最小公倍數

publicstaticintcommonMultiple(intn,intm){

returnn*m/commonDivisor(n,m);//兩數相乘除以最大公約數

}

熱點內容
存儲空間不足某些系統功能 發布:2024-10-16 17:59:24 瀏覽:240
你是怎麼做資產配置的 發布:2024-10-16 17:58:46 瀏覽:869
南京社保原始密碼是什麼 發布:2024-10-16 17:58:00 瀏覽:917
為什麼叫波斯密碼 發布:2024-10-16 17:42:16 瀏覽:371
linux文件共享samba 發布:2024-10-16 17:41:30 瀏覽:825
有密碼的壓縮文件 發布:2024-10-16 17:28:19 瀏覽:726
115瀏覽器視頻緩存 發布:2024-10-16 17:22:59 瀏覽:674
家裡密碼鎖忘記了如何設置新密碼 發布:2024-10-16 17:21:28 瀏覽:98
如何清除微信瀏覽器緩存 發布:2024-10-16 17:07:19 瀏覽:596
安卓轉蘋果為什麼要付99塊錢 發布:2024-10-16 16:43:57 瀏覽:122