Sample, Practice, Fun Java programs for Beginners
Saturday, February 6, 2010
Shortest Function to find if a number is prime
class prime
{
public static boolean PrimeCheck(int a)//a should be greater than 0
{
for(int i=2; i<=a/2; i++)
if(a%i==0)
return false;
return true;
}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment