hasNextInt()方法是判斷控制台接收是否為數字,當你在控制台輸入一個字符的時候,hasNextInt()判斷你輸入這個字符是不是數字,而不是接收值,當if判斷通過之后執行接收,也就是你輸入的那個字符,你也可以試試 public static void main(String[] args) { Scanner input = new Scanner(System.in); if(input.hasNextInt()){ int num = input.nextInt(); System.out.println(num); }else{ System.out.println("請輸入正確數字!~"); } } 當你輸入非數字的字符的時候他會直接進入else塊,所以說hasNextInt()只起到判斷作用而不是接收數據