LFPS - Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Prime Number

Go down

Prime Number Empty Prime Number

Post by Sujith Tue Jul 06, 2010 8:32 pm

Code:

/* Program to print prime numbers from 1 to 10*/
class PrimeNumber
{
    public static void prime(int n)
    {
        int count=0;
        /* This checks the number of times
          * the number gets completely divided
          */
        for(int i=2;i<n;i++)
        {
              if(n%i==0)
              {
                  count++;
              }
        }
        if(count==0)
        {
            System.out.print(n+" ");
        }
    }
    public static void main (String[] args)
    {
        for(int a=1;a<=10;a++)
        {
            prime(a);  // Calling prime() function
        }
    }
}

Variable Table


Variable NameData TypeDescription
count
int
Checks the number of times the number gets completely divided
i
int
Used to iterate the for loop
n
int
Formal Parameter
a
int
Actual Parameter
Sujith
Sujith
LSF Expert
LSF Expert

Posts : 126

http://osalfps.org

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum