-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumber.java
More file actions
40 lines (35 loc) · 1.05 KB
/
Copy pathPrimeNumber.java
File metadata and controls
40 lines (35 loc) · 1.05 KB
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
35
36
37
38
39
40
import java.util.*;
public class PrimeNumber {
int isprime(int n) {
int count = 0, temp;
for (int i = 1; i <= n; i++) {
if (n % i == 0)
count++;
}
if (count == 2)
temp = 1;
else
temp = 0;
return temp;
}
public static void main(String[] args) {
PrimeNumber ob = new PrimeNumber();
Scanner sc = new Scanner(System.in);
System.out.println("ENTER AN INTEGER =");
int n = sc.nextInt();
int ret = ob.isprime(n);
if (ret == 1)
System.out.println("PRIME NUMBER");
else
System.out.println("NOT A PRIME NUMBER");
PrimeNumber ob1 = new PrimeNumber();
System.out.println("ENTER AN INTEGER =");
int n1 = sc.nextInt();
ret = ob1.isprime(n1);
if (ret == 1)
System.out.println("PRIME NUMBER");
else
System.out.println("NOT A PRIME NUMBER");
System.out.println("YOU HAVE ENTERED = " + n + " and " + n1);
}
}