public class Test {
public static void main(String args[]) {
int n, i
Scanner in = new Scanner(System.in)
// 输入字符串个数
n = 10
String[] a = new String[n]
// 依次输入字符串
for (i = 0i <ni++) {
a[i] = in.next()
}
// 排序
sortbybubble(a)
// 输出结果
for (i = 0i <ni++) {
System.out.print(a[i] + " ")
}
System.out.println()
}
// 冒泡排序
private static void sortbybubble(String[] s) {
boolean flag = true
String temp
while (flag) {
flag = false
for (int i = 1i <s.lengthi++) {
if (s[i - 1].compareTo(s[i]) >0) {
temp = s[i - 1]
s[i - 1] = s[i]
s[i] = temp
flag = true
}
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)