Prime Number in Julia

Published on 13 February 2025 (Updated: 13 February 2025)

Welcome to the Prime Number in Julia page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

function err() 
    return "Usage: please input a non-negative integer"
 end
 

function isPrime(num)
# handle 0 and 1
    if num <= 1 
        return "composite"
    end 

# default handler
    for i in 2:sqrt(num) #loop starting at 2, ending at the squareroot of the input
        if (num % i == 0)
            return "composite"
        end
    end
    return "prime"             
end

#check for a valid input
try
    n = parse(Int, ARGS[1])
    if n < 0
        println(err())
    else
        println(isPrime(n))
    end
catch e
    println(err())
end

Prime Number in Julia was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.