-
Notifications
You must be signed in to change notification settings - Fork 1
/
Prime.java
39 lines (30 loc) · 933 Bytes
/
Prime.java
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
import java.util.Scanner;
public class Prime
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a, b, i, j,c;
System.out.println("Enter lower bound of the interval: ");
a = sc.nextInt();
System.out.println("\nEnter upper bound of the interval: ");
b = sc.nextInt();
System.out.println("\nPrime numbers between a and b are");
for (i = a; i <= b; i++)
{
if (i == 1 || i == 0)
continue;
c = 1;
for (j = 2; j <= i / 2; ++j)
{
if (i % j == 0)
{
c = 0;
break;
}
}
if (c == 1)
System.out.println(i);
}
}
}