Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help with finding prime numbers

843785Sep 28 2008 — edited Sep 29 2008
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);
     }
    
} 
            
    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 27 2008
Added on Sep 28 2008
16 comments
287 views