Program
import java.util.Scanner; import java.util.InputMismatchException; public class Scan { // create function readint for reading input value. public static int readInt(String msg) { boolean error=false; int x=0; do { try { // create object of scanner class. Scanner KB=new Scanner(System.in); // enter here. System.out.print("Enter integer : "); x=KB.nextInt(); error=false; } catch(InputMismatchException e) { // accept integer only. System.out.println("Invalid Input..Pls Input Integer Only.."); error=true; } } while(error); return(x); } }
Output
Enter integer : Good Invalid Input..Pls Input Integer Only.. Enter integer : 10 Enter integer : 10
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program
Output
need an explanation for this answer? contact us directly to get an explanation for this answer