A:
public class PrimeNumber {
- private static boolean isPrimeNumber(int num){
- int e = (int)Math.pow(num, 0.5) + 1;
for(int i = 2; i< e; i++){
- /* detect if the number is divided by a integer */
if( (num%i) == 0)
- return false;
return true;
- /* detect if the number is divided by a integer */
public static int getPrimeNumberQuantity(int root, int floor){
- if(floor < 2) return 0;
int q = 0;
for(int i=root; i < floor; i++){
- if(isPrimeNumber(i)){
- q++;
System.out.print(i + ", ");
- q++;
System.out.println();
return q; - if(isPrimeNumber(i)){
}
public static void main(String[] args) {- int m = PrimeNumber.getPrimeNumberQuantity(100, 200);
System.out.println("There are " + m + " prime numbers between 100 and 200.");
- int e = (int)Math.pow(num, 0.5) + 1;
Result:
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
There are 21 prime numbers between 100 and 200.
3 comments:
Hello, this little page on prime numbers really helped me. I had homework on prome numbers 100-200 and this gave me the answers well helping me along the way.
Hello, this little page on prime numbers really helped me. I had homework on prome numbers 100-200 and this gave me the answers well helping me along the way.
omg you just saved my butt fora homework I was doing!
Tysm! ;)
x
Post a Comment