Computer Science, asked by Nokxic, 4 months ago

Write a program to print the prime numbers between 30 and 3000.​

Answers

Answered by Oreki
1

Java:

public class PrimeRange {  

   static boolean isPrime(int number) {

       for (int i = 2; i < number / 2 + 1; i++)

           if (number % i == 0)

              return false;

       return true;

   }

  public static void main(String[ ] args) {

       for (int i = 30; i <= 3000; i++)

           if (isPrime(i))

               System.out.println(i);

   }

}

Python:

def is_prime(number):

   for i in range(2, int(number / 2) + 1):

       if number % 2 == 0:

           return False

       return True

for i in range(30, 3000 + 1):

   if is_prime(i):

       print(i)

Similar questions