Untitled
unknown
plain_text
2 years ago
880 B
12
Indexable
public class PrimeNumbersInRange {
public static void main(String[] args) {
int lowerLimit = 10; // Change the lower limit as needed
int upperLimit = 50; // Change the upper limit as needed
System.out.println("Prime numbers between " + lowerLimit + " and " + upperLimit + " are:");
// Iterate through the range and check for prime numbers
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 num) {
if(num <= 1) {
return false;
}
for(int i = 2; i <= Math.sqrt(num); i++) {
if(num % i == 0) {
return false;
}
}
return true;
}
}Editor is loading...
Leave a Comment