Here you can find the source of getInt()
public static int getInt()
//package com.java2s; //License from project: Open Source License import java.util.InputMismatchException; import java.util.Scanner; public class Main { private static final Scanner keyboard = new Scanner(System.in); /**/*from w w w . j av a 2 s . c o m*/ * Returns an int from standard input, ignoring input that is not an int * @return An int from standard input */ public static int getInt() { int anInt = 0; try { anInt = keyboard.nextInt(); } catch (InputMismatchException ex) { //ignore exception, prompt user again for input if input is incorrect } keyboard.nextLine();//clear the buffer return anInt; } }