如何在java中找到最小公倍数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18214995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find Lowest Common Multiple in java
提问by Legend2525
Can anyone help me, I have no idea how to find the lowest common multiple.
谁能帮我,我不知道如何找到最小公倍数。
For example with the numbers 4 and 5 which is 20. This is what I want to achieve in code.
例如数字 4 和 5 是 20。这就是我想在代码中实现的。
Thank you
谢谢
采纳答案by Kevin
This isn't the best solution but it is a solution see the links in the replies for better solutions
这不是最好的解决方案,但它是一个解决方案,请参阅回复中的链接以获得更好的解决方案
b = 4;
a = 5;
for(int i = 1; i <= b; i++) {
if(i*a % b == 0)
return abs(i*a);
}
Thanks iamnotmaynard for the suggestion
感谢 iamnotmaynard 的建议