import?java.util.Scanner;
public?class?JudgeString?{
public?static?void?main(String[]?args)?{ //?接受鍵盤輸入 Scanner?in?=?new?Scanner(System.in); //?保存輸入數據的List ArrayList<String>?list?=?new?ArrayList<String>(); 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;i<list.size();i++){System.out.println(list.get(i));
} } //?排序函數(冒泡) public?static?void?sort(ArrayList<String>?list)?{ 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);}
}
} }}
已經調試過了,肯定能運行,有不懂得可以問