import java.util.Scanner; //调用java.util.Scanner public class Test { public static void main (String[] args) { Scanner keyboardInput = new Scanner(System.in); //从类Scanner中创建object keyboradInput if (keyboardInput.hasNextInt() == true) //新创建的keyboardInput这个object下,调用hasNextInt() method来判断输入的是不是整数 System.out.println("输入的整数是: " + keyboardInput.nextInt()); //如果是整数,输出这个整数 else System.out.println("输入的不是整数"); } }