Skip to content

Commit 1ba5679

Browse files
committed
Added the code for Prime Numbers in an interval
1 parent 3a91863 commit 1ba5679

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.*;
2+
class primeNumbersInterval
3+
{
4+
public static void main (String[] args)
5+
{
6+
Scanner sc = new Scanner(System.in);
7+
int a, b, ctr = 0, i, j, primes = 0;
8+
a = sc.nextInt();
9+
b = sc.nextInt();
10+
for (i = a; i <= b; i++)
11+
{
12+
for (j = 1; j <= i; j++)
13+
{
14+
if (i % j == 0) {
15+
ctr++;
16+
}
17+
}
18+
if (ctr >= 2)
19+
primes++;
20+
}
21+
System.out.println("Number of primes = " + primes);
22+
}
23+
}

0 commit comments

Comments
 (0)