Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.util.InputMismatchException;
- import java.util.Scanner;
- public class MyScanner {
- Scanner scan;
- public MyScanner( Scanner scan )
- {
- this.scan = scan;
- }
- public String getLine()
- {
- String ret = "";
- try {
- ret = scan.nextLine();
- } catch( Exception e ) {
- System.out.println("Exception: " + e);
- return "";
- }
- return ret;
- }
- public int getInt(int a, int b) {
- int input = getInt();
- while( input < a || input > b ) {
- System.out.println("You must pick a number in-between " + a + " and " + b + "!");
- input = getInt();
- }
- return input;
- }
- public int getInt() {
- int output = 0;
- while( true ) {
- try {
- output = scan.nextInt();
- } catch( InputMismatchException e ) {
- System.out.printf("Please input an integer.\n");
- scan.nextLine();
- continue;
- } catch( Exception e ) {
- System.out.println("Exception: " + e);
- return 0;
- }
- break;
- }
- scan.nextLine();
- return output;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement