- public class HomeWorko1 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入字符串");
- String s = sc.nextLine();
- TreeSet<String> tr = new TreeSet<>(new Mycompara());
- tr.add(s);
- System.out.println(tr);
- fun1(s);
-
-
- }
-
- private static void fun1(String s) {
- char[] ch = s.toCharArray();
- char x;
- for (int i = 0; i < ch.length; i++) {
- for (int j = i+1; j < ch.length; j++) {
- if(ch[i]>ch[j]){
- x=ch[i];
- ch[i]=ch[j];
- ch[j]=x;
- }
- }
-
- }
- System.out.println("-----------");
- System.out.println(ch);
- }
- }
- [color=Red]public class Mycompara implements Comparator<String> {
- public int compare(String o1, String o2) {
-
- while(o1.equals(o2)){
- return 1;
- }
- return o1.compareTo(o2);
- }
- }
复制代码 |
|