# Need help with finding prime numbers

**843785**Sep 28, 2008 3:21 PM

I have seen this question asked several times so i apologize for asking once again but I am very new to programming and could use some help. I know the way I have the extra if statements is not at all efficient but I cannot seem to figure out how to get a nested for statement with a divisor to work. The error I'm getting with this current code is that the second for statement needs to be boolean.

```
/*
*
*
*/
package primenumbers;
/**
*
* @author Owner
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int primecount; //running total of prime numbers
int incrementer; //increment numbers
int sqrtInc; //square root of current increment
int divisor;
//set variables to 0
primecount =0;
incrementer=3;
sqrtInc = (int)Math.sqrt(incrementer);
divisor = 0;
//print 2
System.out.println("2");
for(incrementer = 3; incrementer < 10000; incrementer = incrementer + 1 )
{
if (incrementer % 2 != 0)
if (sqrtInc % 3 != 0)
if (sqrtInc % 5 != 0)
if (sqrtInc % 7 != 0)
if (sqrtInc % 9 != 0)
if (sqrtInc % 11 != 0)
for (divisor = 3; divisor = incrementer; divisor = divisor +1)
if ( incrementer % divisor !=0)
if (incrementer % (Math.sqrt(incrementer)) != 0)
System.out.println(incrementer);
}
}
}
```

- 31 Views
- Tags: none (add)