Monday, September 14, 2015

Generate Prime Numbers list between 1 and 100

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jv.prim;
/**
 * Generate Prime between 1 and 100
 * @author sm rabbi
 */

public class JvPrim {
    /**
     * @param args the command line arguments
     **/

    public static void main(String[] args) {
       
        int a,b,c;
        for(a=1;a<=100;a++)
        {
            c=1;
            for(b=2;b<=a/2;b++)
            {
                if(a%b == 0)
                {
                    c=0;
                    //System.out.println("not prime "+ a + " " + b + " " +a%b);
                    break;
                }
            }
           
            if(c==1)
            {
                System.out.println("prime= " +a);
            }
        }
    }
}
     

No comments:

Post a Comment