title: Java - Continuously check if input is a double
body: <p>So, I've been a little stuck on this method I'm working on.  Basically, I need the method to take in input, check if it's actually a number, then see if it's between the max and min.</p>
  
  <p>The problem I am currently having is when I ask the user to enter a new number, since their input was before 0 or greater than 1,000,000.  When the user enters anything other than a number it crashes.  Any ideas?</p>
  
  <p>If you decide to show me how to fix it with a Try/Catch statement; would you tell me exactly how it works? I'm not 100% sure how those work yet!</p>
  
  <p><strong>The code has been edited with the latest version</strong></p>
  
  <pre><code>public static double inRange( Scanner scan, int min, int max ) {
      double Amount = 0.0;
      boolean isValid = false;
  
      while( isValid == false ) {
          if( scan.hasNextDouble() ) {
              Amount = scan.nextDouble();
              if( Amount &gt; max ) {
                  System.out.print( "Error: You cannot enter a number greater than $1,000,000. Try again: " );
              }
              else if( Amount &lt; min ) {
                  System.out.print( "Error: You cannot enter a negative number. Try again: " );
              }
              else {
                  isValid = true;
                  break;
              }
          }
          else {
              System.out.print( "Error: You must enter a number! Try again: " );
              scan.next();
          }
      }
      return Amount;
  }
  </code></pre>