title: How to check for an integer or a string and if not ask again [Java]
body: <p>There are a bunch of threads throughout the internet on this but I can't make heads or tails of any of them.</p>
  
  <p>As an assignment for an intro to Java course we have been tasked with making a handful of different programs, we were then given them back and told to make them idiot proof.</p>
  
  <p>So for example, we have to use a program to determine what day of the week a random day of any random year will be, (i.e Jan 1 2013 being a Tuesday)</p>
  
  <p>I prompt for three things, Day, Year and Month, I want to make it so that if Day is contains a letter it sends back Invalid and prompts again.</p>
  
  <p>Right now I have it set so that if day is an integer less than one or greater than 31 it asks again, so I don't have a problem with the range, just the NFE.</p>
  
  <p>I have heard that I should use a </p>
  
  <pre><code> Try
      {
      //...
      }
      catch{NumberFormatExcept nFE}
  </code></pre>
  
  <p>but I have no idea how to use that to re-prompt for what I an looking for</p>
  
  <p>Here is a snippet of my code so far</p>
  
  <pre><code>             System.out.print("Enter the day of the month (1-31): ");
               int d = UserInput.nextInt();
  
              do
              {
                  if(d &lt; 1 || d &gt; 31)
                  {
                      System.out.print("That day is invalid, please enter a day between 1 and 31");
                      d = UserInput.nextInt();
                  }
              }while(d &lt; 1 || d &gt; 31);
  </code></pre>
  
  <p>I tried making d a string and using Integer.parseInt(); but that would just parse a into 1, I want to so something like if d.hasNextInt(); continue, but if it hasNextString() reprompt.</p>
  
  <p>AKA</p>
  
  <pre><code>    String d;
      d = UserInput.nextLine();
      int dVar = Integer.parseInt(d);
  </code></pre>
  
  <p>I can't just throw an exception because the objective is to not crash but just prompt again.</p>