title: How to verify that input is a positive integer in Java
body: <p>I am trying to create an input that will Verify the input is an Integer, and that it is positive. Right now i have this. How should i check if the integer is positive</p>
  
  <p>EDIT: Also i need it to keep asking until you enter a positive integer</p>
  
  <pre><code>        /**
   * pre: none
   * post: returns a positive integer as entered by the user
   */
  public static int getInput(){
      int a;
      Scanner scan = new Scanner(System.in);
      System.out.println("Enter Desired Quantity.");
  
      while (!scan.hasNextInt()){ //Checks if input is Integer
          System.out.println("Enter A Positive Integer");
          scan.next();
  
      }
      a = scan.nextInt(); //Assigns entered integer to a
      return a; //replace with correct code
  }
  </code></pre>