Untitled
unknown
plain_text
2 years ago
785 B
7
Indexable
public class Main {
public static int isPrime(int n) {
// Check if the number is less than or equal to 1
if (n <= 1) {
return 0; // Not prime
}
// Check for divisibility from 2 to the square root of the number
for (int i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
return 0; // Not prime
}
}
return 1; // Prime
}
public static void main(String[] args) {
// Test the isPrime function
int number = 17; // Change this to test different numbers
if (isPrime(number) == 1) {
System.out.println(number + " is prime.");
} else {
System.out.println(number + " is not prime.");
}
}
}Editor is loading...
Leave a Comment