36 lines
1.0 KiB
Java
36 lines
1.0 KiB
Java
public class ArrayRecursion {
|
|
|
|
public static void main(String[] args) {
|
|
displayNumberOfPaireNumber(convertCommandArray(args));
|
|
}
|
|
|
|
public static int[] convertCommandArray(String[] args) {
|
|
return convertArray(args, 0, new int[args.length]);
|
|
}
|
|
|
|
private static int[] convertArray(String[] args, int index, int[] integerArray) {
|
|
if(index >= args.length) {
|
|
return integerArray;
|
|
}
|
|
|
|
integerArray[index] = Integer.parseInt(args[index]);
|
|
return convertArray(args, index + 1, integerArray);
|
|
}
|
|
|
|
public static void displayNumberOfPaireNumber(int[] array) {
|
|
System.out.println("Nombre de nombres paires : " + getNumberOfPaireNumber(array, 0));
|
|
}
|
|
|
|
private static int getNumberOfPaireNumber(int[] array, int index) {
|
|
if(index >= array.length) {
|
|
return 0;
|
|
}
|
|
|
|
if(array[index] % 2 == 0) {
|
|
return getNumberOfPaireNumber(array, index + 1) + 1;
|
|
}
|
|
|
|
return getNumberOfPaireNumber(array, index + 1);
|
|
}
|
|
}
|