Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

prime check jaba

 static boolean isPrime(int n){
        boolean result=true;
        if(n <= 1) return false;
        for(int i = 2; i <= n/2; i++){
            if(n % i == 0){
                result = false; //if some number divides it, then prime=false;
                break;
            }
        }
        return result;
    }
Comment

prime check jaba


boolean isPrime(long n) {
    if(n < 2) return false;
    if(n == 2 || n == 3) return true;
    if(n%2 == 0 || n%3 == 0) return false;
    long sqrtN = (long)Math.sqrt(n)+1;
    for(long i = 6L; i <= sqrtN; i += 6) {
        if(n%(i-1) == 0 || n%(i+1) == 0) return false;
    }
    return true;
}

Comment

PREVIOUS NEXT
Code Example
Java :: since when can java command compile 
Java :: Which activity lifecycle method will call in Following Scenario - Launch ActivityA - Press Device Home Button - Again Launch Application * 
Java :: new int [] in java with assigned values 
Java :: error:03000086 
Java :: string array to stream 
Java :: create list of booleans java 
Java :: smaller elements on right hand side leetcode 
Java :: shakescleare merchant of venice 
Java :: execute application jar 
Java :: how to open activity in android studio 
Java :: inject in jsp 
Java :: when does lockdown end 
Java :: Integrity check failed: java.security.NoSuchAlgorithmException: Algorithm HmacPBESHA256 not available jks 
Java :: lombok get error in extended classes¨ 
Java :: how to create a list in java 
Java :: get last element of array java 
Java :: java enum get first element 
Java :: actionlistener java 
Java :: remove action bar android studio 
Java :: java array copy 
Java :: print hashtable in java 
Java :: android clear specific sharedpreference value 
Java :: java 11 initialize map 
Java :: java input character 
Java :: coding collections clear method java 
Java :: java sort 2d array 
Java :: sreekanth kasani 
Java :: javafx textarea font size 
Java :: java yes or no loop 
Java :: system.out.println shortcut 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =