Untitled

mail@pastecode.io avatar
unknown
plain_text
13 days ago
667 B
1
Indexable
Never
public class PrimeChecker {
    public static void main(String[] args) {
        int number = 29; // Change this to the number you want to check
        
        boolean isPrime = true;
        
        if(number <= 1) {
            isPrime = false;
        } else {
            for(int i = 2; i <= Math.sqrt(number); i++) {
                if(number % i == 0) {
                    isPrime = false;
                    break;
                }
            }
        }
        
        if(isPrime) {
            System.out.println(number + " is a prime number.");
        } else {
            System.out.println(number + " is not a prime number.");
        }
    }
}
Leave a Comment