title: Setting a range for an Integer in Java
body: <p>I have the attribute:</p>
  
  <pre><code>private int Number;
  </code></pre>
  
  <p>I want to limit this number so that it can only be between the values 1 - 3.</p>
  
  <p>Would I do this within a method when I set the value or is there a way of predefining that I only want values 1 - 3 to be valid values for this integer?</p>
  
  <p>Many thanks in advance.</p>
  
  <p>Edit:</p>
  
  <p>I want to take an input of a number between 1 -3.</p>
  
  <p>I've tried using a while, do and for loop each of which I can't get to work without getting stuck in an infinite loop.</p>
  
  <p>Here's some example code:</p>
  
  <pre><code>    private int Number;
  
      public void setNumber(int aNumber) {
          int count = 1;
          while (count !=0) {
              if ((aNumber &lt; 1) || (aNumber &gt; 3)) {
                  System.out.println("Value is out of range 1-3");
                  System.out.println("Please try again");
                  break;
              } 
              else {
                  this.Number = aNumber;
                  count = 0;
              }
      }
  }
  </code></pre>