title: Prime number program for java
body: <p>I'm new to programming and need help on a java program. I want my program to return all the prime numbers between 1 and 10.</p>
  
  <pre><code>    for(int i=1; i&lt;=10; i++){
          int factors = 0;
          int j=1;
  
          while(j&lt;=i){
              if(i % j == 0){
                  factors++;
              }
              j++;
          }
          if(factors==2){
              System.out.println(j);
          }
      }
  </code></pre>
  
  <p>Instead of receiving 2,3,5 and 7 I receive 3,4,6,and 8 </p>