prime or not algo added

pull/900/head
Devesh Mehara 2022-10-04 21:39:52 +05:30 committed by GitHub
parent 0c2a362b1f
commit 5942e6f6f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 21 deletions

View File

@ -1,21 +0,0 @@
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<num; i++){
if(num %2 ==0){
return false;
}
}
return true;
}
}

View File

@ -0,0 +1,19 @@
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);
System.out.println(ans!=true?"not-prime":"prime");
}
public static boolean isPrime(int num) {
for (int i = 2; i * i <= num; i++) {
if (num % 2 == 0) {
return false;
}
}
return true;
}
}