title: Finding Primes With An Array
body: <p>I have the following program that prints the prime numbers from 1 to 100 with loops. How could I store the values of those primes in an array and print them out from that array? I tried initializing int[] n =1 but it didn't like that at all. Thanks guys!!!</p>
  
  <pre><code>public class PrimeGenerator 
  {
    public static void main(String[] args) 
    {
      int max = 100;
  
      System.out.println("Generate Prime numbers between 1 and 100. \"1\" is not prime.");
  
      // loop through the numbers one by one
      for (int n = 1; n&lt;max; n++) {
        boolean prime = true;
        //analyzes if n is prime      
  
        for (int j = 2; j &lt; n; j++) {
          if (n % j == 0 ) {
            prime = false;
            break; // exit the inner for loop
          }
        }
  
        //outputs primes
        if (prime &amp;&amp; n != 1) {    
          System.out.print(n + " ");
        }
      }
    }
  }
  </code></pre>