diff --git a/prime_num.java b/prime_num.java new file mode 100644 index 0000000..98788a2 --- /dev/null +++ b/prime_num.java @@ -0,0 +1,22 @@ +public class Main { + + public static void main(String[] args) { + System.out.println(isPrime(5)); + } + public static boolean isPrime(int x){ + if( x <= 1) + return false; + else if( x ==2 ) + return true; + else if (x % 2 == 0) + return false; + + // If not, then just check the odds + for (int i = 3; i <= Math.sqrt(x); i += 2) + { + if (x % i == 0) + return false; + } + return true; + } +}