Saturday 9 November 2013

How to pring first 25 prime number in java

class prime
{
    public static void main(String args[])
    {
        int c=1,i,no,p;
        no=1;
        while(c<=25)
        {
               p=1;
            for(i=2;i<=no/2;i++)
            {
            if(no%i==0)
            {
               p=0;
               break;
            }
             }
        if(p==1)
        {
            System.out.println(no);
        }
         c++;
         no++;
        }
    }               
}

No comments:

Post a Comment

How to change Background color by selecting color from Listview

activitymain.xml file::> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xm...