-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram30.java
More file actions
30 lines (25 loc) · 815 Bytes
/
Program30.java
File metadata and controls
30 lines (25 loc) · 815 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.*;
public class Program30 {
//function to find if number is a prime number or not
public static boolean isPrime(int number) {
if (number <= 1) {
return false;
}
for (int i = 2; i <= Math.sqrt(number); i++) {
if (number % i == 0) {
return false;
}
}
return true;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number to check Prime or Not: ");
int number = scanner.nextInt();
if (isPrime(number)) {
System.out.println(number + " is a prime number");
} else {
System.out.println(number + " is not a prime number");
}
}
}