2012/11/03

How to determine if a number is a prime with regex?

public static boolean prime(int n) {
  return !new String(new char[n]).matches(".?|(..+?)\\1+");
}
The explanation is on the StackOverflow.

No comments: