用JAVA编程:两个自然数a,b,求它们的最小公倍数

来源:百度知道 编辑:UC知道 时间:2024/05/31 15:22:38
要能运行得出结构的程序喔~

public class test {
public static void main(String[] args) {
int a = 0;
int b = 0;
int c = 0;
System.out.print("请输入a:");
try {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
a = Integer.parseInt(br.readLine());
System.out.print("请输入b:");
BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
b = Integer.parseInt(br1.readLine());
}
catch (IOException ex) {
}
if (a > b) {
c = a;
}
else {
c = b;
}
for (int i = c; ; i = i + c) {
if (i % a == 0 && i % b == 0) {
System.out.println("自然数a,b,的最小公倍数:" + i);
break;
}
}
}
}

public class TestMath {
public static void main(String[] args) {
system.out.println(minmultiple(3, 5)