public static voidmain(String[] args) {
Map map = new HashMap();for (Integer i = 10; i < 100; i++) { //两个数一定都是两位数for (Integer j = 10; j < 100; j++) {
Integer total= i *j; //计算乘积if(total>999 && total<10000){ //判断是否是4位数
String totalStr=total.toString(); //将当前数字转成字符串if(total % 100 != 0){ //排除以两个0结尾的情况
String iStr=i.toString();
String jStr=j.toString();
String ijStr= iStr +jStr; //将当前俩个数拼成4个字符的字符串
List list = new ArrayList();for(int x=0;x
list.add(totalStr.charAt(x)); //将两数乘积的四个数字放入list中
}int state = 0;for(int x=0;x
list.remove(indexX); //并且记录重复数字
state++;
}
}if(state == 4){
String resultStr= totalStr + " = " + iStr + "*" +jStr; //state==4说明,乘积中含有两个数组成的所有数字字符
map.put(totalStr, resultStr); //以乘积为key,等式为value存入,达到去重效果
}
}
}
}
}
Set keySet =map.keySet();for(String key:keySet){
System.out.println(map.get(key)); //打印结果
}
}