Files
DEV/DEV3.2/TP02/02_Tableaux/Tableaux.java
Simoes Lukas 91d20e0ba6 tp recursivite
2025-10-09 12:11:25 +02:00

61 lines
1.4 KiB
Java

public class Tableaux {
private int[] tableau;
public Tableaux(int tailleTab) {
this.tableau = new int[tailleTab];
}
public int[] convertitTab(String[] tab, int tailleTab) {
if (tailleTab == 1) {
this.tableau[0] = Integer.parseInt(tab[0]);
return this.tableau;
}
this.tableau[tailleTab-1] = Integer.parseInt(tab[tailleTab-1]);
return this.convertitTab(tab, --tailleTab);
}
public void afficheTab(int[] tab, int increment) {
if (increment == tab.length-1) {
System.out.println(tab[increment]);
} else {
System.out.print(tab[increment] + " | ");
afficheTab(tab, ++increment);
}
}
public int entiersPairs(int increment) {
if (increment == this.tableau.length) {
return 0;
}
if (this.tableau[increment] % 2 == 0) {
return 1 + entiersPairs(++increment);
} else {
return 0 + entiersPairs(++increment);
}
}
public int maximum(int increment, int maxActuel) {
if (increment == this.tableau.length-1) {
if (this.tableau[increment] > maxActuel) {
return this.tableau[increment];
}
return maxActuel;
}
if (this.tableau[increment] > maxActuel) {
return this.maximum(increment+1, this.tableau[increment]);
}
return this.maximum(increment+1, maxActuel);
}
public void afficheTabInverse(int[] tab, int decrement) {
if (decrement == 0) {
System.out.println(tab[0]);
} else {
System.out.print(tab[decrement] + " | ");
afficheTabInverse(tab, --decrement);
}
}
}