一、自己的写法
for(int i=10;i<99;i++){
for(int j=i;j<99;j++){
int a = i*j;
if(a<1000||a>9999)
continue;
String _a = String.valueOf(a);
String str = _a.substring(2,3);
if(!str.equals("00")){
String _i = String.valueOf(i);
String _j = String.valueOf(j);
if(_a.indexOf(_i.substring(0,1))!=-1){
_a = _a.substring(0,_a.indexOf(_i.substring(0,1))) + _a.substring(_a.indexOf(_i.substring(0,1))+1);
}else continue;
if(_a.indexOf(_i.substring(1,2))!=-1){
_a = _a.substring(0,_a.indexOf(_i.substring(1,2))) + _a.substring(_a.indexOf(_i.substring(1,2))+1);
}else continue;
if(_a.indexOf(_j.substring(0,1))!=-1){
_a = _a.substring(0,_a.indexOf(_j.substring(0,1))) + _a.substring(_a.indexOf(_j.substring(0,1))+1);
}else continue;
if(_a.indexOf(_j.substring(1,2))!=-1){
_a = _a.substring(0,_a.indexOf(_j.substring(1,2))) + _a.substring(_a.indexOf(_j.substring(1,2))+1);
}else continue;
if(_a.length()==0){
System.out.println(a +"="+i+"*"+j);
}
}
}
}
二、巧用取余来得到各个位的数字
for(int i=1000;i<10000;i++){
if(i%100==0) continue;
int a = i/1000; //千位
int b = i%1000/100; //百位
int c = i%100/10; //十位
int d = i%10; //个位
if((a*10+b)*(c*10+d)==i){
System.out.println(i+"="+(a*10+b)+"*"+(c*10+d));
}else if((a*10+b)*(d*10+c)==i){
System.out.println(i+"="+(a*10+b)+"*"+(d*10+c));
}else if((b*10+a)*(c*10+d)==i){
System.out.println(i+"="+(b*10+a)+"*"+(c*10+d));
}else if((b*10+a)*(d*10+c)==i){
System.out.println(i+"="+(b*10+a)+"*"+(d*10+c));
}else if((a*10+c)*(b*10+d)==i){
System.out.println(i+"="+(a*10+c)+"*"+(b*10+d));
}else if((a*10+c)*(d*10+b)==i){
System.out.println(i+"="+(a*10+c)+"*"+(d*10+b));
}else if((c*10+a)*(b*10+d)==i){
System.out.println(i+"="+(b*10+d)+"*"+(d*10+b));
}else if((c*10+a)*(d*10+b)==i){
System.out.println(i+"="+(c*10+a)+"*"+(d*10+b));
}else if((a*10+d)*(b*10+c)==i){
System.out.println(i+"="+(a*10+d)+"*"+(b*10+c));
}else if((a*10+d)*(c*10+b)==i){
System.out.println(i+"="+(a*10+d)+"*"+(c*10+b));
}else if((d*10+a)*(b*10+c)==i){
System.out.println(i+"="+(d*10+a)+"*"+(b*10+c));
}else if((d*10+a)*(c*10+b)==i){
System.out.println(i+"="+(d*10+a)+"*"+(c*10+b));
}
}