Last active
August 29, 2015 14:08
-
-
Save arturmkrtchyan/5b7bfa655ccebb1f9647 to your computer and use it in GitHub Desktop.
Functional vs. Imperative Programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean isPrime(final int number) { | |
return number > 1 && | |
IntStream.rangeClosed(2, (int) Math.sqrt(number)) | |
.noneMatch(index -> number % index == 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean isPrime(final int number) { | |
for(int i = 2; i <= Math.sqrt(number); i++) { | |
if(number % i == 0) return false; | |
} | |
return number > 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment