Firstly, thanks a lot for this excellent explanation!. based on this tutorials, I solved in this way to exclude 0,1 and negative minimum input for my exam and output for primeCount. See the code for your info. public class PrimeNumberBtwStartAndEnd { public static void main(String[] args) { primeCount(10, 30); primeCount(11, 29); primeCount(20, 22); primeCount(1, 1); primeCount(5, 5); primeCount(6, 2); primeCount(-10, 6); } public static void primeCount(int start, int end) { int count = 0, flag = 0; for (int n = start; n
Thanks sir, Excellent Explanations but it does not work for 0,1 or any negative numbers! How can it may solved?
0 and 1 are not prime numbers.
Firstly, thanks a lot for this excellent explanation!.
based on this tutorials, I solved in this way to exclude 0,1 and negative minimum input for my exam and output for primeCount. See the code for your info.
public class PrimeNumberBtwStartAndEnd {
public static void main(String[] args) {
primeCount(10, 30);
primeCount(11, 29);
primeCount(20, 22);
primeCount(1, 1);
primeCount(5, 5);
primeCount(6, 2);
primeCount(-10, 6);
}
public static void primeCount(int start, int end) {
int count = 0, flag = 0;
for (int n = start; n
Math.abs
will it work for 2?@@AjayKumar-sg7dd
you can add an if block within the first for loop to check for 0 and 1
How to find range between nth prime number positions