/**
 * 给定一个正整数 int num = (int) (Math.random() * 10000);
 * 求出一个以这个正整数开头,并且能被这个正整数上各个数位(0除外)整除的最小数。 
 * 例如:200     结果:200(200以200开头,能被2整除) 
 * 例如:6238    结果:623808(以6238开头,能被6、2、3、8分别整除) 
 */

解决方案 »

  1.   

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;public class CountTest1 {

    static long theNumber;

    public static void main(String[] args) throws IOException
    {
    System.out.print("请输入一个正整数:");
    theNumber = getLong();
    System.out.print("运算结果为:");
    long result = count(theNumber);
    System.out.println(result);
    }

    public static String getString() throws IOException
    {
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);
    String s = br.readLine();
    return s;
    }

    public static long getLong() throws IOException
    {
    String s = getString();
    return Long.parseLong(s);
    }

    public static long count(long n) throws IOException
    {
    long result = n;
    int t = 1;
    long m = getNumber(n);
    while(true)
    {
    for(long i=result;i<t+result; i++)
    {
    if(i%m==0)
    return i;
    }
    t = t*10;
    result = n*t;
    }
    }

    public static int getNumber(long num) throws IOException
    {
    int result = 1;
    while(num>0)
    {
    int temp = (int)num%10;
    if(temp!=0&&temp!=1)
    result = minLeaseal(result, temp);
    num = num/10;
    }
    return result;
    }

    /**
     * 求两个数的最小公倍数
     * @param num1
     * @param num2
     * @return
     */
    public static int minLeaseal(int num1, int num2)
    {
    int max = num1>num2?num1:num2;
    int min = num1>num2?num2:num1;
    int temp = max;
    while(temp%min!=0)
    {
     temp += max;
    }
    return temp;
    }
    }
      

  2.   


    public class NumberTest {
    /**
     * 取得最小公倍数
     * @param num1
     * @return
     */
    public static int getLeaseal(int num1,int num2){
    int max=num1>num2?num1:num2;
    int min=num1>num2?num2:num1;
    if (min<=0) min=max; 
    for(int i=1;i<=min;i++){
    if (max*i%min==0) return max*i;
    }
    return max*min;
    }
    /**
     * 求一组数的最小公倍数
     * @param num
     * @return
     */
    public static int getLeaseal(int[] num){
    int result=num[0];
    for(int i=1;i<num.length;i++)
    result=getLeaseal(result, num[i]);
    return result;
    }
    /**
     * 将一个整数拆成数组形式
     * @param strNum
     * @return
     */
    public static int[] getNumbers(int num){
    String strNum=Integer.toString(num);
    int[] nums=new int[strNum.length()];
    for (int i = 0; i < nums.length; i++) {
    nums[i]=strNum.charAt(i)-'0';
    }
    return nums;
    }
    /**
     * 计算结果
     * @param num 基数
     * @param leaseal 最小公倍数
     * @return
     */
    private static int getResult(int num, int leaseal) {
    int count=1;
    int result=num;
    out:
    while(true){
    for(int i=0;i<count;i++){
    result=num*count+i;
    //System.out.println(result); //此条语句为调试语句
    if (result%leaseal==0) break out;
    }
    count*=10;
    }
    return result;
    }

    // 主程序入口
    public static void main(String[] args) {
    int num=(int)(Math.random()*100000); //取得随机数
    int leaseal=getLeaseal(getNumbers(num)); //取得最小公倍数
    int result = getResult(num, leaseal);
    System.out.println("取得的随机数是:"+num);
    System.out.println("最小公倍数是:"+leaseal);
    System.out.println("计算结果:"+result);
    }
    }