title: Determining Prime Numbers Java
body: <p>I am writing a program that takes as input an integer, and outputs a message whether the integer entered is prime or not. The algorithm I am using is as follows... <strong>Require:</strong> n>0, <strong>Require:</strong> isPrime &lt;- true, <strong>for</strong> i=2 to sqrt(n) <strong>do</strong>, <strong>if</strong> n%i=0 <strong>then</strong> isPrime &lt;- false <strong>end if</strong> and <strong>end for</strong> Then Print whether the number is Prime or not. Here is my code so far, the code is not working and I am not able to find the problem. </p>
  
  <pre><code>     public static void main(String[] args) {
      Scanner kb = new Scanner(System.in);
      int n;
      System.out.println("Input a positive integer");
      n = kb.nextInt();
  
          while (n&gt;0){
              boolean isPrime = true;
              for (int i =2; i &lt;= n/2;i++){
                  if(n % i == 0){
                      isPrime = false;
                      break;
                  }
              }
              if (isPrime = true){
                  System.out.println("The integer, " + n + ", is a prime");
                  break;
              }
              else{
                  System.out.println("The integer, " + n + ", is not a prime");
                  break;
              }
          }
      }
  }
  </code></pre>
  
  <p>I would be grateful if someone could help, Thanks!</p>