不废话,直接上代码(这是四位数的吸血鬼数字)。。。说一下题目位置,第四章 练习10
//相乘数字值的拆分
int[] counts = new int[4];
//防止重复
int[] ci = new int[2];
int sum = 0;
for(int i =11;i<=99;i++){
out:
for(int j =(1000/i)+1;j<=99;j++){
int count = i*j;
for (int c : ci)if(c==count)continue out;
int c0 = 0;
int a = i/10;
int b = i%10;
int c = j/10;
int d = j%10;
if ((counts[0] = count / 1000) == 0) c0++;
if ((counts[1] = count/100%10) == 0) c0++;
if ((counts[2] = count/10%10) == 0) {
c0++;
if(c0>=2)continue;
}
if ((counts[3] = count%10) == 0) {
c0++;
if(c0>=2)continue;
}
for (int cou =0;cou<counts.length;cou++){
if(a!=Integer.MAX_VALUE&&a==counts[cou]){
a=Integer.MAX_VALUE;
continue;
}else if(b!=Integer.MAX_VALUE&&b==counts[cou]){
b=Integer.MAX_VALUE;
continue;
}else if(c!=Integer.MAX_VALUE&&c==counts[cou]){
c=Integer.MAX_VALUE;
continue;
}else if(d!=Integer.MAX_VALUE&&d==counts[cou]){
d=Integer.MAX_VALUE;
continue;
}
continue out;
}
//数组所需内存不够,扩容一下
try {
ci[sum]=count;
}catch (ArrayIndexOutOfBoundsException e){
ci = Arrays.copyOf(ci,ci.length*2);
ci[sum]=count;
}
sum++;
System.out.println(count+" = "+i+" * "+j);
}
}
作为一个毕业生,要为java继续奋斗!!!!!!加油加油!!!