Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

isprime check formula java

  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

isprime java

static boolean isPrime(int n){
	for (int i = 2; i <= Math.sqrt(n); i++)
		if (n % i == 0) return false;
	return n > 1;
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to convert an object into string with different fields in java 
Java :: IntStream.generate 
Java :: spinner get item text 
Java :: primefaces custom validator 
Java :: how to iterate over a string in java 
Java :: circle line intersection java 
Java :: use view binding in fragment 
Java :: reverse string in java 
Java :: jackson object to string 
Java :: iterator constructor java 
Java :: how to import jframe in java 
Java :: java loop object 
Java :: sreekanth kasani 
Java :: how to iterate hashset in java 8 
Java :: how to close android app programmatically 
Java :: How to convert timestamp to time in android studio 
Java :: how to not open key board on start 
Java :: array to array list 
Java :: Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.spi.LoggerContextFactory.isClassLoaderDependent()Z 
Java :: jave arrayList to Array 
Java :: how to make an activity default in android studio 
Java :: java code to print hello world 
Java :: java split for multiple characters 
Java :: java get ip address 
Java :: java substring 
Java :: get certain character from string java 
Java :: play sound in java 
Java :: java reverse linked list 
Java :: indexoutofboundsexception java 
Java :: set jframe fullscreen 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =