-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ12_PrimeNoToRange.java
More file actions
43 lines (29 loc) · 1.05 KB
/
Q12_PrimeNoToRange.java
File metadata and controls
43 lines (29 loc) · 1.05 KB
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
// 12. Program to print all prime numbers between given range.
import java.util.Scanner;
public class Q12_PrimeNoToRange {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("12. Program to print all prime numbers between given range.\n\n");
int num1, num2, i, j, flag;
System.out.print("Enter start point to print prime number: ");
num1 = sc.nextInt();
System.out.print("\nEnter end point to print prime number: ");
num2 = sc.nextInt();
System.out.print("\nPrime numbers between " + num1 + " and " + num2 + " are: ");
for (i = num1; i <= num2; i++) {
if (i == 1 || i == 0)
continue;
flag = 1;
for (j = 2; j <= i / 2; ++j) {
if (i % j == 0) {
flag = 0;
break;
}
}
if (flag == 1){
System.out.print(i + " ");
}
}
System.out.print("\nThank You");
}
}