-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime.java
More file actions
34 lines (30 loc) · 944 Bytes
/
prime.java
File metadata and controls
34 lines (30 loc) · 944 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
import java.util.Scanner;
public class prime {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = sc.nextInt();
boolean is_prime = true;
if (num == 1) {
System.out.println(num + " is not prime number");
is_prime = false;
}
if (num == 2) {
System.out.println(num + " is prime number");
is_prime = true;
} else {
for (int i = 3; i < num; i = i + 2) {
System.out.println(i);
if (num % i == 0) {
System.out.println(num + " is not a prime number");
is_prime = false;
break;
}
}
if (is_prime) {
System.out.println(num + " is prime number");
}
}
sc.close();
}
}