package cn.itcast.demo;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
public class Demo8 {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入:");
while (true) {
String line = sc.nextLine();
if ("quit".equals(line)) {
break;
}else{
sort(line);
}
}
}
public static void sort(String line) {
TreeSet<String> ts = new TreeSet<>(new Comparator<String>() {
@Override
public int compare(String s1, String s2) {
int num = s1.length() - s2.length();
return num == 0 ? 1 : num;
}
});
ts.add(line);
System.out.println(ts);
}
}
写到这不会写了 想了很久不会啊 真实越学越后退 求 大神指导
|
|