我有 3 类电话号码,即 Golden、Special 和 Normal。我正在尝试做的是当用户输入电话号码时,它会自动确定电话号码属于哪个类别。让我举一个黄金类别编号的示例:AA001234(AA 代表 2 位数字,具有相同的数字,如 11、22、33 等)。这是我得到的
public static void main(String[] args) {
Scanner userinput = new Scanner(System.in);
System.out.println("Enter Telephone Number");
String nophone = userinput.next();
String Golden = "(\\d{2})002345"; // <-- how to write the code if the user
//enter the same digit for the first 2 number, it will belong to Golden category?
String Special1 = "12345678|23456789|98765432|87654321|76543210";
if (nophone.matches(Golden)) {
System.out.println("Golden");
}
else if (nophone.matches(Special1)) {
System.out.println("Special 1");
}
else {
System.out.println("Normal");
}
}