Untitled

mail@pastecode.io avatar
unknown
plain_text
16 days ago
763 B
1
Indexable
Never
public class PrimeNumbers {
    public static void main(String[] args) {
        int lowerLimit = 10; // Lower limit
        int upperLimit = 50; // Upper limit

        System.out.println("Prime numbers between " + lowerLimit + " and " + upperLimit + " are:");
        for (int num = lowerLimit; num <= upperLimit; num++) {
            if (isPrime(num)) {
                System.out.print(num + " ");
            }
        }
    }

    // Function to check if a number is prime
    public static boolean isPrime(int number) {
        if (number <= 1) {
            return false;
        }
        for (int i = 2; i <= Math.sqrt(number); i++) {
            if (number % i == 0) {
                return false;
            }
        }
        return true;
    }
}
Leave a Comment