20 import ca.uqac.lif.cep.functions.FunctionException;
21 import ca.uqac.lif.cep.functions.UnaryFunction;
33 public class IsPrime extends UnaryFunction<Number,Boolean>
50 super(Number.class, Boolean.class);
61 public Boolean getValue(Number x)
64 int max = (int) Math.sqrt(k);
65 for (
int n = 2; n <= max; n++)
76 public static void main(String[] args)
throws FunctionException
79 Object[] value =
new Object[1];
83 ip.evaluate(
new Integer[]{3}, value);
87 System.out.printf(
"Return value of the function: %b\n", value[0]);
88 ip.evaluate(
new Integer[]{8}, value);
89 System.out.printf(
"Return value of the function: %b\n", value[0]);
Create a custom unary function that checks if a number is prime.
static final transient IsPrime instance
This is optional.