Prime Number
LFPS - Forum :: Study Corner :: Computers :: Java :: Snippets
Page 1 of 1
Prime Number
- 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 Name | Data Type | Description |
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 |
LFPS - Forum :: Study Corner :: Computers :: Java :: Snippets
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Feb 14, 2012 9:02 pm by Sujith
» Kolaveri Di
Tue Nov 22, 2011 5:11 pm by Sujith
» Plane of Remembrance
Mon May 23, 2011 7:44 am by Sujith
» Board Exam Results 2011
Fri May 13, 2011 10:19 pm by Sujith
» Source Code
Wed May 04, 2011 8:06 pm by Sujith
» Rio
Wed May 04, 2011 8:04 pm by Sujith
» Fast and Furious 5
Wed May 04, 2011 7:56 pm by Sujith