title: find nth prime number
body: <p>I've written the following code below to find the nth prime number. Can this be improved in time complexity?</p>
  
  <p>Description:</p>
  
  <p>The ArrayList arr stores the computed prime numbers. Once arr reaches a size 'n', the loop exits and we retrieve the nth element in the ArrayList. Numbers 2 and 3 are added before the prime numbers are calculated, and each number starting from 4 is checked to be prime or not.</p>
  
  <pre><code>public void calcPrime(int inp) {
      ArrayList&lt;Integer&gt; arr = new ArrayList&lt;Integer&gt;(); // stores prime numbers 
                                                        // calculated so far
      // add prime numbers 2 and 3 to prime array 'arr'
      arr.add(2); 
      arr.add(3);
  
      // check if number is prime starting from 4
      int counter = 4;
       // check if arr's size has reached inp which is 'n', if so terminate while loop
      while(arr.size() &lt;= inp) {
          // dont check for prime if number is divisible by 2
          if(counter % 2 != 0) {
              // check if current number 'counter' is perfectly divisible from 
             // counter/2 to 3
              int temp = counter/2;
              while(temp &gt;=3) {
                  if(counter % temp == 0)
                      break;
                  temp --;
              }
              if(temp &lt;= 3) {
                  arr.add(counter);
              }
          }
          counter++;
      }
  
      System.out.println("finish" +arr.get(inp));
      }
  }
  </code></pre>