Answers for "prime numbers'"

0

prime numbers

function isPrime(num) {
    if(num <= 2){
        return num + " is not prime"
    }
    for(let i = 2; i < num; i++){
        if(num % i == 0){
            return num + " is not prime"
        }
    }
    
    return num + " is prime"      
}
console.log(isPrime(4))
console.log(isPrime(6))
console.log(isPrime(0))
console.log(isPrime(-9))
console.log(isPrime(43))
console.log(isPrime(-2))
console.log(isPrime(-1))
Posted by: Guest on October-11-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language