-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime.java
More file actions
28 lines (28 loc) · 753 Bytes
/
Prime.java
File metadata and controls
28 lines (28 loc) · 753 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
import java.util.*;
class Prime
{
public static void main(String X[])
{
Scanner sc = new Scanner(System.in);
int num;
System.out.print("Enter the Number : ");
num = sc.nextInt();
if(num < 0)
System.out.println("The given number " + num + " is a negative number");
else if(num == 0)
System.out.println("The given number " + num + " is a Zero");
else if(num == 1)
System.out.println("The given number " + num + " is neither prime nor Composite");
else
{
int i, fc = 0;
for(i = 2; i <= (num / 2); i++)
if(num % i == 0)
fc++;
if(fc == 0)
System.out.println("The given number " + num + " is a prime number");
else
System.out.println("The given number " + num + " is a composite number");
}
}
}