Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // User input validation - for number of x to process
- // input: no input, but this method listens to users' keyboard input.
- // output: number of x to process, x is an integer bigger than 0.
- public static int numberOfXToProcess() {
- String numberOfXString;
- int numberOfX;
- while(true) {
- // listen to input and save the values
- Scanner keyboard = new Scanner(System.in);
- System.out.println("Please enter the number of x values to process:");
- numberOfXString = keyboard.nextLine();
- try{
- // convert the string to integer
- numberOfX = Integer.parseInt(numberOfXString);
- // return the int if it's bigger than 0; give alert if not
- // your code goes here
- } catch(NumberFormatException nFE) {
- System.out.println("Your input has to be an integer bigger than 0. Try again.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement