nextInt()方法 从键盘获取 int 数据 nextLine()方法 从键盘获取字符串 hasNextInt()方法 从键盘获取的数据是否为 int 数据 例如: if(sc.hasNextInt()){ int x=sc.nextInt(); System.out.println("数字是:"+x); }else if(sc.hasNextLine()){ String x=sc.nextLine(); System.out.println("字符串是:"+x); }