APL/DEV 3.2/TP02/Tableaux/Tableaux.java
2022-10-07 11:14:09 +02:00

49 lines
1.4 KiB
Java

import java.util.Arrays;
public class Tableaux {
public static int[] getTab(String[] args, int index, int[] tab) {
if (index == 0) {
if (args.length == 0) return new int[0];
tab = new int[args.length];
tab[0] = Integer.parseInt(args[0]);
getTab(args, index + 1, tab);
} else if (index < args.length) {
tab[index] = Integer.parseInt(args[index]);
getTab(args, index + 1, tab);
}
return tab;
}
public static int maxN(int[] tab, int index) {
if (index < tab.length) {
int n = maxN(tab, index + 1);
return tab[index] > n ? tab[index] : n;
} else return Integer.MIN_VALUE;
}
public static int getEven(int[] tab, int index, int n) {
if (index == 0) n = 0;
if (index < tab.length) {
return (tab[index] % 2 == 0 ? 1 : 0) + getEven(tab, index + 1, n);
} else return 0;
}
public static void showTab(int[] tab, int index) {
if (index < tab.length) {
showTab(tab, index + 1);
System.out.print(tab[index] + " ");
} if (index == 0) System.out.print("\n");
}
public static void main(String[] args) {
int[] tab = getTab(args, 0, null);
System.out.println(getEven(tab, 0, 0));
System.out.println(maxN(tab, 0));
showTab(tab, 0);
}
}