Skip to content

Instantly share code, notes, and snippets.

@ptahchiev
Created October 8, 2016 14:06
Show Gist options
  • Save ptahchiev/2c52182feb7db9a63d882b12659afba5 to your computer and use it in GitHub Desktop.
Save ptahchiev/2c52182feb7db9a63d882b12659afba5 to your computer and use it in GitHub Desktop.
sample2
public class Sample2 {
public static void main(String[] args) {
int number = 17;
System.out.println(imperative(number));
System.out.println(declarative(number));
}
public static boolean imperative(int number) {
for (int i = 2; i < number / 2; i++) {
if (number % i == 0) {
return true;
}
}
return false;
}
public static boolean declarative(int number) {
return IntStream.range(2, number / 2).filter(e -> number % 2 == 0).findFirst().orElse(-1) != -1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment