Skip to content

Commit 26e2291

Browse files
find the prime number between 20 to 50
find the prime number between 20 to 50 Co-Authored-By: Manish Upadhyay <ermanishupadhyay@gmail.com>
1 parent 8bc4f2b commit 26e2291

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: src/JavaPrograms/PrimeNumberIntervals.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package JavaPrograms;
2+
3+
public class PrimeNumberIntervals {
4+
5+
public static void main(String[] args) {
6+
// find the prime number between 20 to 50
7+
int low = 20;
8+
int high = 50;
9+
10+
while(low < high) {
11+
boolean flag = false;
12+
for(int i=2; i<low/2; i++) {
13+
if(low % i == 0) {
14+
flag = true;
15+
break;
16+
}
17+
}
18+
if(!flag) {
19+
System.out.println(low + " ");
20+
}
21+
low++;
22+
}
23+
24+
}
25+
26+
}

0 commit comments

Comments
 (0)