-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumRangeFunc.java
More file actions
32 lines (28 loc) · 934 Bytes
/
Copy pathPrimeNumRangeFunc.java
File metadata and controls
32 lines (28 loc) · 934 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
import java.util.Scanner;
public class PrimeNumRangeFunc {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Lower limit ::");
int low = sc.nextInt();
System.out.println("Higher limit ::");
int high = sc.nextInt();
// for loop approach
System.out.println("Prime numbers in given range are :");
while (low < high) {
boolean flag = false;
for (int i = 2; i <= low / 2; ++i) {
// condition for nonprime number
if (low % i == 0) {
flag = true;
break;
}
}
if (!flag && low != 0 && low != 1) {
System.out.print(low + " ");
}
++low;
}
}
public void primeNumRangeFunc(int lower, int higher){
}
}