From 11ad4ef3219f258d1270ec1b9cc9c106073b8a16 Mon Sep 17 00:00:00 2001 From: Aindri11 <115166023+Aindri11@users.noreply.github.com> Date: Wed, 19 Oct 2022 09:49:22 +0530 Subject: [PATCH] Update isPrime.java Made the code a bit less complex and less time consuming --- isPrime.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/isPrime.java b/isPrime.java index ff51cc521..14676eea5 100644 --- a/isPrime.java +++ b/isPrime.java @@ -1,14 +1,14 @@ import java.util.*; -public class B{ +public class Main{ public static void main(String args[]){ - System.out.println("Enter a Number"); + System.out.println("Enter a Number:"); Scanner sc = new Scanner(System.in); int n = sc.nextInt(); - if(isPrimeNumber(n)) - System.out.println("This is a Prime Number"); + if(isPrimeNumber(n)==true) + System.out.println(n+" is a Prime Number"); else - System.out.println("This is not a Prime Number"); + System.out.println(n+" is not a Prime Number"); } static boolean isPrimeNumber(int n) { @@ -16,8 +16,6 @@ static boolean isPrimeNumber(int n) { return false; if (n==2) return true; - if (n%2==0) - return false; for(int i=3;i*i<=n;i+=2) { if(n%i==0) return false; @@ -25,3 +23,4 @@ static boolean isPrimeNumber(int n) { return true; } } +