Matt23

isPrime

Oct 24th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.34 KB | None | 0 0
  1. public class Main
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         int n = 2750159;
  6.         boolean isPrime = true;
  7.         for (int i = 2; i <= Math.sqrt(n); i++)
  8.         {
  9.             if (n % i == 0)
  10.             {
  11.                 isPrime = false;
  12.                 break;
  13.             }
  14.         }
  15.        
  16.         System.out.println( (isPrime) ? "prime" : "non-prime );
  17.    }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment