title: Any easier way of finding prime numbers than this?
body: <p>is there a more <strong>efficient, cleaner/elegant</strong> way of finding prime numbers than this? The code works fine, but I just wrote what seemed most logical to me and I can't figure out any other way, but to be honest it just doesn't look nice :P. I know coding isn't the most elegant of activities.</p>
  
  <p>Here's my main method:</p>
  
  <pre><code>import java.util.Scanner;
  public class DisplayPrimeNumbers
  {
      public static void main(String[] args)
      {
          Scanner scan = new Scanner(System.in);
          System.out.print("Enter an integer that you'd like the system to print the prime numbers till: ");
          String input1 = scan.nextLine();
          int input = Integer.parseInt(input1);
  
          PrimeGenerator prime = new PrimeGenerator(input);
  
          for (int i = 1; i &lt; input ; i++)
          {
              if(prime.isPrime())
              {
              System.out.println(prime.getNextPrime());
              }
          }
          System.out.println(1);
  
      }
  }
  </code></pre>
  
  <p>Here's my class:</p>
  
  <pre><code>public class PrimeGenerator 
  {
      private int number;
  
      public PrimeGenerator(int n)
      {
          number = n;
      }
  
      public int getNextPrime ()
      {
          return number+1;
      }
  
  
      public boolean isPrime()
      {
          for(int i = 2; i &lt; number; i++)
          {
              if (number % i == 0)
              {
                  number--;
                  return false;
              }
          }
      number--;   
      return true;    
      }
  } 
  </code></pre>