Untitled

mail@pastecode.io avatar
unknown
plain_text
12 days ago
884 B
1
Indexable
Never
import java.util.Scanner;

 class PrimeNumbers {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the lower limit: ");
        int lowerLimit = scanner.nextInt();
        System.out.print("Enter the upper limit: ");
        int upperLimit = scanner.nextInt();

        System.out.println("Prime numbers between " + lowerLimit + " and " + upperLimit + " are:");
        for (int i = lowerLimit; i <= upperLimit; i++) {
            if (i < 2)
                continue;
            boolean isPrime = true;
            for (int j = 2; j <= i / 2; j++) {
                if (i % j == 0) {
                    isPrime = false;
                }
            }
            if (isPrime) {
                System.out.print(i + " ");
            }
        }
        System.out.println();
    }
 }
Leave a Comment