-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime01.java
More file actions
37 lines (37 loc) · 787 Bytes
/
Copy pathprime01.java
File metadata and controls
37 lines (37 loc) · 787 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
35
36
37
import java.util.*;
class prime01
{
int checkPrime(int a)
{
int b=a; int k=0;
for(int i=1;i<=a;i++)
{
if(a%i==0)
{
k++;
}
}
if(k==2)
{
return 1;
}
else{
return 0;
}
}
public static void main (String [] args)
{
prime01 Math=new prime01();
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int show=Math.checkPrime(n);
if(show==1)
{
System.out.println("It is a prime number");
}
else{
System.out.println("It is not a prime number");
}
}
}