Problem Statement
A prime number is one that has exactly two divisors: 1 and itself. The first few primes are 2, 3, 5, 7, 11.
Given start and end, how many prime numbers are there between those bounds, inclusive?
Definition
- Class:
- PrimesBetween
- Method:
- count
- Parameters:
- int, int
- Returns:
- int
- Method signature:
- int count(int start, int end)
- (be sure your method is public)
Constraints
- start will be between 1 and 100, inclusive.
- end will be between start and 100, inclusive.
Examples
2
11
Returns: 5
These are the primes listed in the problem statement.
8
10
Returns: 0
Note that none of 8, 9, or 10, are prime, so we return 0.
12
20
Returns: 3
The primes here are 13, 17, 19.
1
100
Returns: 25
20
30
Returns: 2
23 and 29.
1
1
Returns: 0