title: Find a prime number with loops
body: <p>I'am new to Java and my homework was to make a program where the user input a number and the program check if the number is a prime number or not. </p>
  
  <p>I have to use any loop and JOptionPane for input.</p>
  
  <p>I've managed to write this code and it works:</p>
  
  <pre><code>import static javax.swing.JOptionPane.*;
  public class Programmeringsoppgave5 {
  
      public static void main(String[] args) {
          int number = 0; 
          String readNumber = showInputDialog("Write a number and exit with ESC");
  
          while (readNumber != null){
          number = Integer.parseInt(readNumber);
              if (number != 0 &amp;&amp; (number == 1 || number == 2)){
                  System.out.println("Number " + readNumber + " is a prime number.");
              } else if (number % 2 == 0){
                  System.out.println("Number " + readNumber + " is not a prime number.");
              } else if (number % 2 == 1){
                  System.out.println("Number " + readNumber + " is a prime number.");
              }//end if-test
              readNumber = showInputDialog("Write a number and exit with ESC");
          }//end while    
      } //end method
  }//end class
  </code></pre>
  
  <p>I was wondering if there was any easier or better ways to write this program?</p>