import java.util.ArrayList;
import java.util.Scanner;
public class JudgeString {
public static void main(String[] args) {
// 接受键盘输入
Scanner in = new Scanner(System.in);
// 保存输入数据的List
ArrayListlist = new ArrayList ();
System.out.println("请输入字符串,输入“end”为结束:");
// 获取每次输入的字符串
String temp = in.nextLine();
// 获取输入的所有字符串
while (!temp.equals("end")) {
list.add(temp);
temp = in.nextLine();
}
// 调用排序函数
sort(list);
//输入结果
System.out.println("排序后的结果为:");
for(int i = 0;iSystem.out.println(list.get(i));
}
}
// 排序函数(冒泡)
public static void sort(ArrayListlist) {
String temp = "";
for (int i = 0; i < list.size(); i++) {
for (int j = 0; j < list.size() - 1; j++) {
if (list.get(i).compareToIgnoreCase(list.get(j)) > 0) {
temp = list.get(i);
list.set(i, list.get(j));
list.set(j, temp);
}
}
}
}
}
已经调试过了,肯定能运行,有不懂得可以问
import java.util.Scanner;
public class Test8 {
public static void main(String[] args) {
Scanner c = new Scanner(System.in);
StringBuffer sbf = new StringBuffer();
while(true){
System.out.println("请输入一组字符串:");
String s = c.nextLine();
if(s.equals("end")){
break;
}else{
sbf.append(s);
}
}
String sc = sbf.toString();
char[]cs = sc.toCharArray();
for(int i = cs.length-1;i>=0;i--){
System.out.print(cs[i]);
}
}
}
不知道你所谓的字典顺序是什么意思? 我这个是把所有字符串组一块,倒序打印