exercice: Poignées de main

This commit is contained in:
Rémi Heredero 2022-03-07 17:15:30 +01:00
parent 4843b0aea5
commit 45b2a3e527
3 changed files with 22 additions and 1 deletions

View File

@ -3,5 +3,9 @@
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
],
"cSpell.words": [
"complexite",
"Poignee"
]
}

View File

@ -1,7 +1,24 @@
package C10_Tri_et_complexite.C102_Complexite_algorithmique;
// Nombre de poignées de mains échangées pour n personnes.
public class Poignee_de_main {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
new Poignee_de_main(10);
}
private int n;
private long checks = 0;
Poignee_de_main(int n){
this.n = n;
compute();
System.out.println("Poignées de mains échangée: " + checks);
}
private void compute() {
for (int i = n-1; i >= 1; i--) {
checks += i;
}
}
}