title: java arrays error: /tmp/java_959p0x/TestPrimeDividers.java:30: error: cannot find symbol return arr;
body: <p>Can you please help me figure out why I am getting an error in this Java program?</p>
  
  <pre><code>public class TestPrimeDividers {
      public static boolean isPrime(long n) {
          boolean flag = true;
          for (int i = 2; i &lt; n &amp;&amp; flag ; i++) {
              if ((n % i) == 0)
                  flag = false;
          }
          return flag;
      }
      public static long [] primeDividers(long n) {
          if (isPrime(n)) {
              long arr[] = new long [0];
              return arr;
          } else {
              int j = 0;
              for (int i = 2 ; i &lt; n; i++)
                  if (isPrime(i))
                      j++;
              long arr[] = new long [j];
              j = 0;
              for (int i = 2; i &lt; n; i++)
                  if (isPrime(i)) {
                      arr[j] = i;
                      j++;
                  }
  
          }
          return arr;
      }
      public static void main(String[] args) {
          long arr [] = primeDividers(6);
      }
  }
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>/tmp/java_959p0x/TestPrimeDividers.java:30: error: cannot find symbol
  return arr;
         ^
    symbol:   variable arr
    location: class TestPrimeDividers
  1 error
  </code></pre>