JAVA编程输入三个名字按字母顺序自动排序

有3个要完成。
1,按字母顺序自动给三个名字排序。
2,首字母自动大写,后面的自动小写
3,如果输入的不是英文字母会显示error 。
直接可以截图给我
下面是两个例子,完成的效果要跟这个一样,谢谢各位大神帮忙

public static void main (String [] args){
List<String> list = new ArrayList<String>();
Scanner scan = new Scanner(System.in);
System.out.println("Please input the first name: ");
list.add(getName(scan.next(),"first"));
System.out.println("Please input the second name: ");
list.add(getName(scan.next(),"second"));
System.out.println("Please input the third name: ");
list.add(getName(scan.next(),"third"));
scan.close();
//剔除为null的对象(因为不合法的名称被设置为null)。
//此处为何用ite迭代删除?原因参考http://blog.csdn.net/longyulu/article/details/8315068
Iterator<String> ite = list.iterator();
while(ite.hasNext()){
String s = ite.next();
if(s == null){
ite.remove();
}
}
//排序
Collections.sort(list);
//输出最终结果
System.out.print("The names are :");
for (String s : list) {
System.out.print("\""+s+"\" ");
}

}

private static String getName(String name , String index) {
String regEx="^[A-Za-z]+$"; //纯字母正则表达式
Pattern pat=Pattern.compile(regEx);  
if(pat.matcher(name).matches()){
//全部转为小写
name = name.toLowerCase();
//提取第一个字母并转换大写
String first = (name.charAt(0)+"").toUpperCase();
name = first+name.substring(1);
System.out.println(name+" is the "+index+" name.");
}else{
name = null;
System.out.println("Error: The "+index +" name was not accepted.");
}
return name;
}
//控制台结果:
Please input the first name: 
tsKd
Tskd is the first name.
Please input the second name: 
ukf90
Error: The second name was not accepted.
Please input the third name: 
admin
Admin is the third name.
The names are :"Admin" "Tskd"

追问

cannot find symbol
List list = new ArrayList();
error: cannot find symbol
Iterator ite = list.iterator();
error: cannot find symbol

温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-09-19
这个很简单,不过我现在没那么多时间,不急的话可以晚上帮你解决。追问

可以,后天才要弄,我今天问下,对IF else掌握的不好

追答

你是要用java语言写吧?

追问

嗯,用if else写

第2个回答  2014-09-19
同意楼上.作业还是自己做比较好,掌握得比较牢.
第3个回答  2014-09-19
作业要自己做