nelsonaustin8179 nelsonaustin8179
  • 23-06-2019
  • Computers and Technology
contestada

Write a JAVA program to generate the list of prime numbers between 100 and 1000 ?

Respuesta :

Аноним Аноним
  • 23-06-2019

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);

}

Answer Link

Otras preguntas

Explain how to get the width of the room which is 320 square feet and the width of the room is 4/5 of its length.
How do you find cumulative effect of two or more forces acting on an object
In which of the following sentences is 'but' used as a preposition? A. I wanted to leave, but I was embarrassed to do so. B. We discovered that Candy will do an
What item was rationed until 1947? a sugar b fish c tires d oil
what is the chance of rolling a 4 with a single die three times in a row
Which president''s administration was involved in the Teapot Dome scandal? A. Theodore Roosevelt B. William McKinley C. Warren Harding D. William Howard Taft.
what types of eukaryotic cells have vacuoles that act like lysosomes
What number is 44% of 25
why aren't lipids considered polymers?
how many times greater is the value of 6 in 640,700 than the value of the 4 in 67,040