/** * 因式分解,如果为素数则返回“” * * @param num * @return */ public static String factorize(int num) { int m = num = num >= 2 ? num : 2; String factors = ""; for (int i = 2; (m > 1) && (i * i <= num);) { if (m % i != 0) { i++; continue; } m /= i; factors = (factors.equals("")) ? "" + i : factors + " * " + i; } if (1 < m && m < num) { factors = factors + " * " + m; } return factors; }?