我面临一个问题。当我键入一个名称时,例如:“大卫”。它成功终止,但是当我输入名称为“大卫”时,它显示错误。你们对此有什么想法/解决方案吗?
import java.util.Scanner;
public class test {
public static void main(String args[]) {
Scanner sc = new Scanner(System. in );
String name;
int length;
char alpha;
boolean status = true;
do {
System.out.print("Enter name : ");
name = sc.nextLine();
length = name.length();
for (int count = 0; count < length; count++) {
alpha = name.charAt(count);
if (alpha < 'a' || alpha > 'z')
System.out.print("Error");
status = (true);
}
} while (status == false);
}
}