-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNo.java
More file actions
43 lines (38 loc) · 962 Bytes
/
PrimeNo.java
File metadata and controls
43 lines (38 loc) · 962 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
38
39
40
41
42
43
/**
* PrimeNo
*/
import java.util.Scanner;
public class PrimeNo {
// function to find prime number
// static public void findPrime(int a) {
// for (int i = 2; i < a; i++) {
// if (a % i == 0) {
// System.out.println("Number is not a prime.");
// break;
// // System.out.println(i);
// } else {
// System.out.println("Number is prime.");
// break;
// // System.out.println(i);
// }
// }
// }
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
System.out.println("Enter the number: ");
int x = obj.nextInt();
if (findPrime(x)) {
System.out.println("Prime");
} else {
System.out.println("not");
}
}
public static boolean findPrime(int a) {
for (int i = 2; i < a; i++) {
if (a % i == 0) {
return false;
}
}
return true;
}
}