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

CAN SOMEONE PLEASE HELP ME WITH NUMBER 2
Please help me guys, thanks
What simplified expression is equivalent to the expression -1/2 (-3/2 +6+1)−3?
Rosa bought 1 pound of cashews and 2 pounds of peanuts for $10. At the same store, Sabrina bought 2 pounds of cashews and 1 pound of peanuts for $11. Find the c
Select yes or no to state whether each data set is likely to be normally distibuted
order these from least to greatest 6. 6/25,6.17,5.171,25/4​
Hannah was asked to make d the subject of the formulad-7=4d+3/ecomplete hannah's steps to her final answer​
Which type of pill is she use in this public service ad? Examine the public service ad. A. Emotional appeal. B. Ethical appeal. C. Logical appeal. D. Proactive
Parents warn a new babysitter that their son, dennis, is very aggressive and mischievous. as a result of this initial expectation, the babysitter starts calling
Create a system of linear equations that has one solution of y=2x+1 and y=2x+2