title: Prime number detector is not working
body: <p>I am trying to make a program that will determine if an inputted number is prime or not. It always returns that it is not prime. What am i doing wrong?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public class PrimeNumber {
      public static void main(String[] args) {
          System.out.println("Enter a number");
          Scanner sc = new Scanner(System.in);
          int x = sc.nextInt();
          sc.close();
  
          boolean y = false;
          for(int i = 2; i &lt;= x; i++) {
              if(x % i == 0) {
                  y = true;
              }
              y = false;
          }
  
          if (y = true) {
              System.out.print(x + " is not a prime number");
          }
          else {
              System.out.print(x + " is a prime number");
          }
      }
  }
  </code></pre>