Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Kanishk Kunal

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

isPrime

// finding whether 'n' is prime or not

   1  
   2  private boolean isPrime (int n)
   3  {
   4     if (n<=1) return false;
   5     if (n==2) return true;
   6     if (n%2==0) return false;
   7     int m=(int)Math.round(Math.sqrt(n));
   8  
   9     for (int i=3; i<=m; i+=2)
  10        if (n%i==0)
  11           return false;
  12  
  13     return true;
  14  }
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS