Answers for "prime numbers"

12

prime numbers

public class Prime {
    public static void main(String[] args) {

        int num = 29;
        boolean flag = false;
        for(int i = 2; i <= num/2; ++i){
            if(num % i == 0){
                flag = true;
                break;
            }
        }

        if (!flag)
            System.out.println(num + " is a prime number.");
        else
            System.out.println(num + " is not a prime number.");
}}
Posted by: Guest on May-25-2020
2

Prime Number

Numbers -- Prime Number
Write a method that can check if a number is prime or not
 
Solution:
public static boolean primeNumber(int num) {

    if(num <= 1){
        return false;
    }

    for(int i = 2; i < num; i++) {
        if(num % i == 0) {
            return false;
        }
    }

    return true;

}
Posted by: Guest on September-29-2021
5

prime number

def is_prime(n):
  if(n<0):
    print("n is not a nature number!")
    return False
  for i in range(1,ceil(n/2)+1):
    if (i != n and i != 1 and n%i == 0):
      return False
  return True
print(is_prime(int(input("number>>"))))
Posted by: Guest on July-10-2021
23

prime numbers

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97 ...
Posted by: Guest on January-07-2021
2

prime numbers

A number only divisible by 1 and itself
Posted by: Guest on May-04-2021
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

Browse Popular Code Answers by Language