Java Program To Display Prime Numbers Between Intervals Using Function
Java Program To Display Prime Numbers Between Intervals Using Function
++low;
}
}
if(num % i == 0) {
flag = false;
break;
}
}
return flag;
}
}
Output
23 29 31 37 41 43 47
In the above program, we've created a function named checkPrimeNumber() which takes a
parameter num and returns a boolean value.
Based on the return value, the number is printed on the screen inside the main() method.
Note that inside the checkPrimeNumber() method, we are looping from 2 to num/2. This is
because a number cannot be divided by more than it's half.