From 6ea39b3750af7766371aaf6bfd1326ba7dd44214 Mon Sep 17 00:00:00 2001 From: Rishabh Raj Kumar <108469021+Rishabh-raj-kumar@users.noreply.github.com> Date: Sat, 28 Oct 2023 18:01:30 +0530 Subject: [PATCH] Create PrimeNumberCheck.java --- PrimeNumberCheck.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 PrimeNumberCheck.java diff --git a/PrimeNumberCheck.java b/PrimeNumberCheck.java new file mode 100644 index 00000000..8d508200 --- /dev/null +++ b/PrimeNumberCheck.java @@ -0,0 +1,24 @@ +public class PrimeNumberCheck { + + public static void main(String[] args) { + System.out.println(isPrime(19)); // true + System.out.println(isPrime(49)); // false + } + + public static boolean isPrime(int n) { + if (n == 0 || n == 1) { + return false; + } + if (n == 2) { + return true; + } + for (int i = 2; i <= n / 2; i++) { + if (n % i == 0) { + return false; + } + } + + return true; + } + +}