package seven_topic; import java.util.*; public class p_19_1 { public static void main(String[] args) { @SuppressWarnings("resource") Scanner reader = new Scanner(System.in); System.out.println("请输入学生学号: "); String a = reader.next(); String LF4 = a.substring(a.length() - 4);// 后四 String lf2 = LF4.substring(0, 2);// 后四前二 boolean b = true; try { @SuppressWarnings("unused") int n1 = Integer.parseInt(LF4);// 后四位转整 int n2 = Integer.parseInt(lf2); if (n2 >= 06 && n2 <= 22) { b = true; } else { b = false; } } catch (Exception e) { b = false; } if (a.startsWith("aabcddef") && b == true) { System.out.println("学生学号录入成功!"); } else { System.out.println("学生学号格式错误!"); } } }