title: Strange java number generation
body: <p>I am trying to create a program that generates all multiples of prime numbers in a given range. However, I encounter a program for large numbers.</p>
  
  <pre><code>boolean[] array = new boolean[25000];
  for(int k = 2; k &lt;= n; k++){
        if(isPrime(k)){
          //int p = k;
          for(int i = 0; i &lt; 1000000; i++){
            if(i*k &lt;= n){
              System.out.println("k: "+k+" i: "+i + " k*i: " + (i*k ));
              array[i*k] ^= true;
            }
          }
        }
      }
  </code></pre>
  
  <p>This code generates and prints all multiples of prime numbers in given range by the user. In my test I am using n = 25000</p>
  
  <pre><code>protected boolean isPrime(int number){
      if (number == 2 || number == 3) return true;
      //check if n is a multiple of 2
      if (number%2==0) return false;
      //if not, then just check the odds
      for(int i=3;i*i&lt;=number;i+=2) {
          if(number%i==0)
              return false;
      }
      return true;
    }
  </code></pre>
  
  <p>This is my function that checks if a number is a prime.</p>
  
  <p>Here is a short output of the last few lines when n = 25000</p>
  
  <pre><code>k: 2153 i: 3 k*i: 6459
  k: 2153 i: 4 k*i: 8612
  k: 2153 i: 5 k*i: 10765
  k: 2153 i: 6 k*i: 12918
  k: 2153 i: 7 k*i: 15071
  k: 2153 i: 8 k*i: 17224
  k: 2153 i: 9 k*i: 19377
  k: 2153 i: 10 k*i: 21530
  k: 2153 i: 11 k*i: 23683
  k: 2153 i: 997438 k*i: -2147483282
  Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -2147483282
  </code></pre>
  
  <p>I cannot find a solution (or the code that makes it bug) on the last generation. After k = 2153 and i = 11, the next number is k=2153(that is fine) but i jumps to 997438. I can't find what is making it go that high. Any ideas appreciated.</p>