【发布时间】:2016-11-17 00:10:56
【问题描述】:
我正在尝试排除员工编号 XXX-L,其中 x 是 0-9 范围内的数字,L 是 A-M 范围内的字母。我正在尝试使此代码正常工作。但我无法输入有效的输入。
import java.util.Scanner;
import java.util.InputMismatchException;
public class ObjectOrinetPrograming
{
public static void main( String [] args )
{
Scanner input = new Scanner (System.in);
System.out.println("Please Enter elements: ");
String employeenumber = input.nextLine();
while (employeenumber.length() != 5)
{
System.out.println("invalid input; lenght, Try again:");
employeenumber = input.nextLine();
}
while (employeenumber.charAt(4) != ('A'|'B'|'C'|'D'|'E'|'F'|'G'|'H'|'I'|'J'|'K'|'L'|'M'))
{
System.out.print("invalid input; charrecter match, try again:");
employeenumber = input.nextLine();
}
while (employeenumber.charAt(0) == '-')
{
System.out.println("Invalid Input; form, try again:");
employeenumber = input.nextLine();
}
}
}
【问题讨论】:
标签: java string validation char