Bonjour, je voudrais savoir comment je peux transformer ce programme itératif en un programme récursif. Je vous remercie d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 public int chercheEntierConsecutif_v2(int nb) { int x0 = -1; if (nb > 0 && nb <= tab.length) { int i = 0; while (x0 < 0 && i <= (tab.length - nb)) { if (compteOccurrences(i) >= nb) { x0 = tab[i]; } i++; } } return x0; } public int compteOccurrences(int i) { boolean b = true; int c = 0; int x = tab[i]; while (b && i < tab.length) { b = (tab[i] == x); if (b) { c++; i++; } } return c; }
Partager