public static void checkWord() { //接受输入 Scanner scanner = new Scanner(System.in); //输入的字符串 String str = scanner.nextLine().trim(); //如果字符串长度大于1 if (str.length() > 1) { //不符合要求,提示 System.out.println("输入字符串"); } //如果字符为a到z中间,提示小写字母 else if (str.matches("[a-z]")) { System.out.println("输入小写字母"); } //如果字符为A到Z中间,提示大写字母 else if (str.matches("[A-Z]")) { System.out.println("输入大写字母"); } //如果字符为0到9中间,提示数字 else if (str.matches("[0-9]")) { System.out.println("输入数字"); } //输入的字符不合法,非数字和字母 else { System.out.println("输入既字符串写字母数字"); }}