exercice: Poignées de main
This commit is contained in:
parent
4843b0aea5
commit
45b2a3e527
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -3,5 +3,9 @@
|
||||
"java.project.outputPath": "bin",
|
||||
"java.project.referencedLibraries": [
|
||||
"lib/**/*.jar"
|
||||
],
|
||||
"cSpell.words": [
|
||||
"complexite",
|
||||
"Poignee"
|
||||
]
|
||||
}
|
||||
|
Binary file not shown.
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user