56.1k views
1 vote
Write a JAVA program to generate the list of prime numbers between 100 and 1000 ?

User Piemonkey
by
6.1k points

1 Answer

4 votes

First of all, we will need a function that checks if a number is prime or not:

boolean isPrime(int n){

for(int i=2; i<=math.sqrt(n); i++){

if(n % i == 0) return false;

}

return true;

}

Then, in the main program, we will call this function with all the desired inputs, and we will print the prime numbers:

for(int n=100; n<= 1000; n++){

if(isPrime(n)) print(n);

}

User Tapas Jena
by
6.7k points