Java Scanner Usage parameterInput(int start, int end)

Here you can find the source of parameterInput(int start, int end)

Description

parameter Input

License

Open Source License

Declaration

public static int parameterInput(int start, int end) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.InputMismatchException;
import java.util.Scanner;

public class Main {
    public static int parameterInput(int start, int end) {
        Scanner in = new Scanner(System.in);
        int choice = 0;
        boolean done = false;
        // Read a parameter value (int) from the keyboard
        while (!done) {
            try {
                choice = in.nextInt();/*from ww  w. j av a2s  .  co m*/
            } catch (InputMismatchException e) {
                in.nextLine();
                System.out
                        .println("Wrong type of input. Please try again.");
                continue;
            }
            if (choice > end || choice < start) {
                System.out
                        .println("Wrong choice, there is no such option. Please try again.");
            } else {
                done = true;
            }
        }
        return choice;
    }
}

Related

  1. menu()
  2. nextChar(Scanner s)
  3. nextInt(final Scanner sc)
  4. numberOfLines(String text)
  5. OperasiMasukan()
  6. parse_str_vector(String str_vector)
  7. parseDailyData(final List lines, final List priceValues, final List dailyPriceDate)
  8. parseExperimentName(String name)
  9. parseQueryString(String queryString)