终于做出来了,不知大家还有没有更好的方法?
public class AdditionTest{ public static void main(String[] args) {
Addition.createNum();
}
}
class Addition{
public static void createNum(){
int i,j;
for(i=1234,j=21319;i<=78680&&j<=98765;i++,j++){//21319=20085+1234 78680=98765-20085
if(test(i,j)&&i+20085==j){
System.out.println(i+"+20085="+j);
}
}
}
public static boolean test(int num1,int num2){
int a[]=new int[]{0,0,0,0,0,0,0,0,0,0};
int tag=0;
for(int i=10000;i>0;i/=10){
//把num1,num2各位数字分解,作标为a[]的下标,如果a[]在这个下标的值已被修改为1,证明有重复值,返回false
if(a[num1/i]==1)
return false;
a[num1/i]=1;
if(a[num2/i]==1)
return false;
a[num2/i]=1;
num1%=i;
num2%=i;
}
return true;
}
}
/*
 * 结果是
 *  14982+20085=35067
 * 27951+20085=48036
  37941+20085=58026
  41973+20085=62058
  51963+20085=72048
  64932+20085=85017 * */

解决方案 »

  1.   

    刚接触JAVA,在上面的基础上改了一下,练练手public class temp
    {
        public void select()
        {
            for(int i = 1234; i <= 98765; ++i )
            {
                int j = i + 20085;
                    if(test(i, j))
                        System.out.println(i+"+20085="+j);
            }
        }

        public boolean test(int n1, int n2)
        {
            boolean flag = true;

            int[] a = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

            for(int i = 0; i < 5; ++i)
            {
                if(a[n1 % 10] == 1)
                {
                    flag = false;
                    break;
                }
                a[n1%10] = 1;

                if(a[n2 % 10] == 1)
                {
                    flag = false;
                    break;
                }
                a[n2%10] = 1;

                n1 /= 10;
                n2 /= 10;
            }

            return flag;
        }

        public static void main(String[] args)
        {
            new temp().select();
        }
    }