Java examples for java.lang:int prime
Deterministic Prime testing.
//package com.java2s; public class Main { /**/* w ww. j av a 2 s. co m*/ * Deterministic Prime testing. * * @param num * @return */ public static boolean chkPrime(int num) { if (num == 1) return false; if (num == 2 || num == 3) return true; if (num % 2 == 0) return false; else if (num % 3 == 0) return false; for (int i = 5; i * i <= num; i += 2) { if (num % i == 0) return false; } return true; } }