62,636
社区成员




public static void main(String[] args) {
String[] text = { "bc", "de", "ac", "abc", "ab", "e", "a" };
String temp = "";
for (int i = 0; i < text.length; i++) {
for (int j = i+1; j < text.length; j++) {
if (text[i].compareTo(text[j]) > 0) {
temp = text[i];
text[i] = text[j];
text[j] = temp;
}
}
}
System.out.println(Arrays.toString(text));
}
package com.xy.example;
import java.util.Arrays;
public class Test2 {
public static void main(String[] args) {
String[] text = { "a", "ab", "ac", "abc", "de", "bc", "e" };
for (int i = 0; i < text.length; i++) {
String temp = text[i];
for (int j = i; j < text.length - i; j++) {
if (temp.compareTo(text[j]) > 0) {
text[i] = text[j];
text[j] = temp;
}
}
}
System.out.println(Arrays.toString(text));
}
}