-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimeNumber.java
More file actions
34 lines (30 loc) · 873 Bytes
/
primeNumber.java
File metadata and controls
34 lines (30 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Scanner;
public class primeNumber {
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;
if(n!=2 && n%2==0)
return false;
for(int i=2;i<=Math.sqrt(n);i++){ // algorithm
if(n%i==0)
return false;
}
return true;
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(isprime(n))
System.out.println("Prime number");
else
System.out.println("not a prime number");
sc.close();
}
}