因为“蔄”为上下结构,需要加识别码F,希祥运望能到销宴森你。
你亏亩用的是哪个五笔输入法,用的是“万能五笔”里面有,其他的输入法软件里也应该有吧,你在属性或设置里调一下
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"
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)