Last active
January 23, 2023 13:37
-
-
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
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
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