package sql;
import java.util.ArrayList;
import java.util.List;
public class Testheidong2 {
public static void main(String args []){
final List<Integer> listFrist = new ArrayList<>();
listFrist.add(1);
for(int k=10001;k<100000;k++){
try {
List<Integer> resultList= new ArrayList<>();
resultList =resultArray(k, resultList, k, 1);
if(resultList.size()>0){
boolean isUser = false;
for(Integer first:listFrist){
if(resultList.contains(first)){
isUser =true;
}
}
if(!isUser){
System.out.print("[");
for (int i = 0; i < resultList.size(); i++) {
if(i==resultList.size()-1){
System.out.print(resultList.get(i));
}else{
if(i==0){
listFrist.add(resultList.get(i));
}
System.out.print(resultList.get(i)+",");
}
}
System.out.println("]");
}
}
} catch (Exception e) {
continue;
}
}
}
public static List<Integer> resultArray(int a,List<Integer> result,int b,int cishu) throws Exception{
if(cishu<5){
if(a == maxminCha(b)){
result.add(Integer.valueOf(b));
return result;
}else{
result.add(Integer.valueOf(b));
return resultArray(a,result,maxminCha(b),++cishu);
}
}else{
return null;
}
}
/**
* 计算一个5位数的最大最小 差值
* @param a
* @return
* @throws Exception
*/
public static int maxminCha(int a) throws Exception{
char[] c=String.valueOf(a).toCharArray();
int max=0;
int min=0;
char t ='0';
for(int i=0;i<c.length;i++){
for(int j=0;j<c.length;j++){
if(c[j]>c[i]){
t = c[i];
c[i] =c[j];
c[j] =t;
}
}
}
for(int i=0;i<c.length;i++){
max+=Integer.valueOf(String.valueOf(c[i]))*Math.pow(10, c.length-1-i);
min+=Integer.valueOf(String.valueOf(c[i]))*Math.pow(10, i);
}
int cha=min-max;
return cha;
}
}
|