-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime2.java
More file actions
30 lines (25 loc) · 832 Bytes
/
prime2.java
File metadata and controls
30 lines (25 loc) · 832 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
import java.util.Scanner;
public class prime2 {
public static int prime(int a) {
int count = 0;
for (int i = 2; i <= a / 2; i++) {
if (a % i == 0) {
count++;
break;
}
}
return count;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number to check whether it is a prime number or not: ");
int a = scanner.nextInt();
int count = prime(a);
if (count == 0) {
System.out.println("The given number " + a + " is a prime number.");
} else {
System.out.println("The given number " + a + " is not a prime number.");
}
scanner.close();
}
}