title: Trying to write code that asks the user for a number, determines if it's prime, and lists the prime numbers between one and that number
body: <p>For some reason when I test this, the second if statement always prints every number between one and the number the user input as not prime, even if it is. However, the third if statement correctly states if the user's number is prime or not. Is there something wrong that I am doing?</p>
  
  <pre><code>public static void main(String[] args) {
  
      @SuppressWarnings("resource")
      Scanner input = new Scanner(System.in) ;
  
      System.out.println("intput a number") ;
      int number = input.nextInt() ;
  
      int counter = 0 ;
      int counter2 = 0 ;
  
      for (int i = 1 ; i &lt;= number ; i++) {
          for (int j = 1 ; j &lt;= i ; j++) {
              if (i % j == 0 ) {
                  counter ++ ;
              }
              else if (i%j != 0) {
              }
          }
          if (counter != 2) {
              System.out.println( i+" is not prime") ;
          }
          if (counter == 2) {
              System.out.println(i+", is a prime") ;
          }
          System.out.println("\n") ;
          if (number % i == 0) {
              counter2 ++ ;
          }
      }
      if (counter2 != 2) {
          System.out.println( number+" is not prime") ;
      }
      else if (counter2 == 2){
          System.out.println( number+" is a prime") ;
      }
  }
  </code></pre>