diff --git a/algorithms/Java/Maths/check-prim-or-not.java b/algorithms/Java/Maths/check-prim-or-not.java new file mode 100644 index 00000000..72d61f2b --- /dev/null +++ b/algorithms/Java/Maths/check-prim-or-not.java @@ -0,0 +1,21 @@ +import java.util.*; + +public class Main{ + public static void main(String[] args) { + Scanner scn = new Scanner(System.in); + int num = scn.nextInt(); + boolean ans = isPrime(num); + if(ans =! true) System.out.println("not prime"); + else System.out.println("prime"); + } + + + public static boolean isPrime(int num){ + for(int i=2; i*i