import java.util.*;
public class Main {
enum DIRECTION {
ASCEND, DESCEND
};
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
if(isSame(str)){
System.out.println(str+" - "+str+" = 0000");
} else {
String a;
String b;
int c;
do{
a=doOrder(str, DIRECTION.DESCEND);
b=doOrder(str, DIRECTION.ASCEND);
c=Integer.parseInt(a)-Integer.parseInt(b);
System.out.println(a+" - "+b+" = "+c);
str=String.valueOf(c);
} while(c!=6174);
}
}
private static boolean isSame(String str) {
boolean b = true;
char c = str.charAt(0);
for (int i = 1; i < str.length(); i++) {
if (c != str.charAt(i)) {
b = false;
break;
}
}
return b;
}
private static String doOrder(String str, DIRECTION d) {
final int rev;
if (d == DIRECTION.ASCEND) {
rev = 1;
} else {
rev = -1;
}
ArrayList<String> list = new ArrayList<>();
for (int i = 0; i < str.length(); i++) {
list.add(str.substring(i, i+1));
}
list.sort(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return rev * o1.compareTo(o2);
}
});
StringBuilder sb=new StringBuilder();
for(String i:list){
sb.append(i);
}
return sb.toString();
}
}
提示编译错误,eclipse没有出错。
编译错误:您提交的代码无法完成编译
第53行: error:
cannot find symbol
指向list.sort(new Comparator