import java.util.Scanner; public class Reader { public static void main(String[] args) { Scanner scan = new Scanner(System.in); //创建对象 System.out.println("input your string: "); String str = scan.nextLine(); System.out.println(str); System.out.println("input your number: "); int num = scan.nextInt(); System.out.println(num); System.out.println("input your number: "); if (scan.hasNextInt()) //判断输入的是否是整数 { System.out.println(scan.nextInt()); } else System.out.println("not an integer."); } }