您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

详细介绍java中最小公倍数与最大公约数

2025/9/10 19:27:40发布17次查看
java中最小公倍数与最大公约数
import java.util.scanner; /** * created by admin on 2017/3/26. */ public class test02 { public static int mincommon(int a, int b) { int c, m = a * b; if(a<b){ int t=a; a=b; b=t; } if (a % b == 0) return a; else { while (b != 0) { c = a % b; a = b; b = c; } return m/a; } } public static void main(string[] args) { int a=1,b=1; scanner scanner=new scanner(system.in); while (a!=0||b!=0){ a=scanner.nextint(); b=scanner.nextint(); int result=mincommon(a,b); system.out.println(result); system.out.println((a*b/result)); } } }
以上就是详细介绍java中最小公倍数与最大公约数的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product