1 package cn.check.com; 2 3 import java.util.Scanner; 4 5 public class AgeDemo { 6 7 public static void main(String[] args) { 8 // TODO Auto-generated method stub 9 String ages = "18-24"; 10 11 String regex = "-";// 这里的意思是在每个-处进行分解 12 String[] strarry = ages.split(regex);// 进行分解 13 // 转换成int类型 14 int startage = Integer.parseInt(strarry[0]); 15 int endage = Integer.parseInt(strarry[1]); 16 // 键盘录入 17 Scanner sc = new Scanner(System.in); 18 System.out.println("请输入数字:"); 19 int ss = sc.nextInt(); 20 if (ss <= endage && ss >= startage) { 21 System.out.println("你输入的数字正确"); 22 } else { 23 System.out.println("你输入的数字太大或者太小"); 24 } 25 26 } 27 28 }