boolean flag = true;
while (flag) {
System.out.println("请输入一个字符串");
String s = sc.nextLine();
for (int i = 0;i< s.length()-1;i++){
char chr = s.charAt(i);
if(chr >= 'a' && chr <= 'z' || chr >= 'A' && chr <= 'Z'){
flag = false;
break;
}else {
flag = true;
}
System.out.println("输入错误,请重新输入带字母的字符串")
}
} |
|