Skip to content

Commit 8bc4f2b

Browse files
Prime Number
Prime Number Co-Authored-By: Manish Upadhyay <ermanishupadhyay@gmail.com>
1 parent 34b0b9a commit 8bc4f2b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/JavaPrograms/PrimeNumber.java

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package JavaPrograms;
2+
3+
public class PrimeNumber {
4+
5+
public static void main(String[] args) {
6+
// Prime Number : the number which is divisible by 1 and itself.
7+
// 2,3,5,7,11,13...........etc.
8+
// 1 is not a prime number
9+
10+
int num = 3;
11+
boolean flag = false;
12+
13+
for(int i=2; i<=num/2; i++) {
14+
if(num % i == 0) {
15+
flag = true;
16+
break;
17+
}
18+
}
19+
if(!flag) {
20+
System.out.println(num + " is a prime number");
21+
}
22+
else {
23+
System.out.println(num + " is not a prime number");
24+
}
25+
26+
}
27+
28+
}

0 commit comments

Comments
 (0)