import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Pattern;
public class Test {
public static void main(String[] args) {
String[] keyWords = new String[]{"class", "interface", "public", "extends", "private", "protect", "while", "if", "for", "abstract", "final"};
Scanner sc = new Scanner(System.in);
boolean flag = true;
while(flag) {
System.out.print("Enter a variable name (q to quit):");
String str = sc.nextLine();
if("q".equals(str)) {
flag = false;
break;
}
if("".equals(str) || str == null) {
System.out.println("legal");
}else {
String rexOne = "[a-zA-Z]";
String rexTwo = "[0-9]";
String rexThree = "[_$]";
String rexFour = "[a-z]";
if(str.replaceAll(rexOne, "").replaceAll(rexTwo, "").replaceAll(rexThree, "").length() > 0) {
System.out.println("legal,but uses poor style");
}else {
String firstStr = str.substring(0, 1);
if(Pattern.compile(rexTwo).matcher(firstStr).find()) {
System.out.println("legal,but uses poor style");
}else if(Arrays.asList(keyWords).contains(str)){
System.out.println("legal,but uses poor style");
}else {
if(str.replaceAll(rexOne, "").replaceAll(rexTwo, "").length() == 0 && Pattern.compile(rexFour).matcher(firstStr).find()) {
System.out.println("professional");
}else {
System.out.println("legal");
}
}
}
}
}
}
}
有人可以给一下备注吗