Skip to content

Instantly share code, notes, and snippets.

@TGITS
Last active January 23, 2023 13:37
Show Gist options
  • Save TGITS/17509c3e29413760768d820dc4a549de to your computer and use it in GitHub Desktop.
Save TGITS/17509c3e29413760768d820dc4a549de to your computer and use it in GitHub Desktop.
Exemple d'un fichier de scripts jshell créé à parti d'une sauvegarde de snippets
import java.util.stream.Collectors;
import java.util.stream.IntStream;
int sumOfDividers(int value){
return IntStream.rangeClosed(1, value).filter(i -> value % i == 0).sum();
}
var maxItems = 100;
System.out.println("Perfect Numbers up to : " + maxItems);
String list = IntStream.rangeClosed(1, maxItems).filter(num -> sumOfDividers(num) == 2 * num).mapToObj(i -> ((Integer) i).toString()).collect(Collectors.joining(", "));
System.out.println(">> " + list);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment