Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Inputs
- {
- /**
- Gets the choice that the user provided, or null if the
- user didn't provide a valid choice.
- @param input the user input
- @param maxChoice the maximum valid choice, e.g. "D" if there
- are four choices.
- @return the user input if it was a valid choice (i.e. length 1
- and between "A" and maxChoice), null otherwise
- */
- public String getChoice(String input, String maxChoice)
- {
- String regex = "[A-" + maxChoice + "]";
- return (input.matches(regex)) ? input : null;
- }
- }
Add Comment
Please, Sign In to add comment