title: java - Array index is out of bounds
body: <p>Why does this code show the error message java.lang.ArrayIndexOutOfBoundsException: -2146737495!!
  I think that the size of array is sufficient enough.</p>
  
  <pre><code>class Main {
  static int[] ara = new int[1000010];
  
  
  public static void seive(){
      for(int i = 0; i &lt;= 1000000; i++)
          ara[i] = 0;
      ara[1] = 1;
  
      for(int i = 2; i &lt;= 1000000; i ++)
      {
          if(ara[i] == 0)
          {
              for(int j = i * i; j &lt;= 1000000; j += i)
                  ara[j] = 1;
          }
      }
  }
  public static void main(String[] args)
  {
      seive();
  }
  </code></pre>
  
  <p>}</p>