From 5fbf6934f7bf8df5ff03ec6a4fe069c0149adddb Mon Sep 17 00:00:00 2001 From: Devesh Mehara <96515074+MehraDevesh2022@users.noreply.github.com> Date: Mon, 3 Oct 2022 09:57:00 +0530 Subject: [PATCH] added new algo. into : algorithms/java/Maths dir.. For a given number N check if it is prime or not. A prime number is a number which is only divisible by 1 and itself. Example 1: Input: N = 5 Output: 1 Explanation: 5 has 2 factors 1 and 5 only. PR Checklist: My submission is formatted according to the guidelines in the contributing guide My addition is on refer on the language README.md file My addition does not have a spelling problem My submission has a proper and user-friendly description of the algorithm My submission has the time complexity of the algorithm My submission has sample input-output of the program (NOT FOR PYTHON) What kind of change does this PR introduce? (check at least one) Bugfix New algorithm Optimization in previous algorithms Code style update Refactor Documentation Other, please describe: Briefly describe the changes in this PR code added for longest palindromic substring --- algorithms/Java/Maths/check-prim-or-not.java | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 algorithms/Java/Maths/check-prim-or-not.java 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