Java examples for java.util:Scanner
Scanner int Scan
//package com.java2s; import java.util.*; public class Main { public static int intScan(Scanner scan, String print) { int number = 0; boolean run = true; String satisfy;/*w w w .jav a 2 s . co m*/ while (run) { try { System.out.print(print); number = scan.nextInt(); run = false; } catch (Exception ex) //Catch to make sure that the user inputs a integer for the number (not something else). { System.out.println("Please enter an integer."); run = true; satisfy = scan.next(); //Satisfy the read. } } return number; } }