求最小公倍数
正整数A和正整数B 的最小公倍数是指能被A和B整除的最小的正整数值,设计一个算法,求输入A和B的最小公倍数。
输入描述:
输入两个正整数A和B。输出描述:
输出A和B的最小公倍数。示例1
输入
5 7输出
35示例2
输入
2 4输出
4Java 编程
package cn.net.javapub.demo2.demo;
/**
* @author: shiyuwang
* @url: http://javapub.net.cn
*/
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String str = reader.readLine();
String[] strarray = str.split(" ");
int x = Integer.valueOf(strarray[0]);
int y = Integer.valueOf(strarray[1]);
if (x == y) {
System.out.println(x);
} else if (x > y) {
for (int i = 1; i <= y; i++) {
if (i * x % y == 0) {
System.out.println(i * x);
break;
}
}
} else {
for (int i = 1; i <= x; i++) {
if (i * y % x == 0) {
System.out.println(i * y);
break;
}
}
}
}
}展示效果:

















