-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime.java
More file actions
26 lines (25 loc) · 716 Bytes
/
Copy pathPrime.java
File metadata and controls
26 lines (25 loc) · 716 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
import java.util.*;
public class Prime {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter n :");
int n = sc.nextInt();
if(n==2){
System.out.println("n is prime number.");
}
else{
boolean isPrime = true;
for(int i=2;i<=Math.sqrt(n);i++){
if (n % i == 0) {
isPrime=false;
}
}
if (isPrime == true) {
System.out.println("n is a prime number.");
}
else {
System.out.println("n is not a prime number.");
}
}
}
}