-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctions5.java
40 lines (35 loc) · 922 Bytes
/
Functions5.java
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
// Make a Function to check if a Number is Prime or Not.
import java.util.*;
public class Functions5 {
public static void checkPrime(int n) {
boolean isPrime = true;
for(int i=2; i<=n/2; i++)
{
if (n%i==0) {
isPrime = false;
break;
}
}
if(isPrime)
{
if(n == 1)
{
System.out.println("This is Nither Prime Not Composite");
}
else
{
System.out.println("This is a Prime Number");
}
}
else
{
System.out.println("This is Not a Prime Number");
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
checkPrime(n);
sc.close();
}
}