exercice: Poignées de main
This commit is contained in:
		| @@ -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