# Prime Number in Mathematica

Published on 17 January 2023 (Updated: 17 January 2023)

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

## Current Solution

``````(* Code *)

(* This is provided by a Mathematica built-in PrimeQ.  Only a function to provide the 'user interface' is needed: *)

primeNumberMain = s \[Function] Module[
{e = "Usage: please input a non-negative integer"},
Catch[
Replace[
PrimeQ@
(* convert string to integer, or throw *)
If[StringMatchQ[s, DigitCharacter ..],
FromDigits[s],
Throw[e]],
{False -> "Composite", True -> "Prime"}]]];

(* Valid Tests *)

Print /@ primeNumberMain /@ {
"0",
"1",
"2",
"4",
"7",
"4011",
"3727"
};

(* Invalid Tests *)

palindromicNumberMain["6.7"]
palindromicNumberMain["-7"]

``````

Prime Number in Mathematica was written by:

• Ben Hekster

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.