public class Methode5 { static double moyenne(double[] tab, int nbElem) { double somme = 0.0; for(int i = 0; i < nbElem; i++) somme += tab[i]; return somme / nbElem; } static int nombre(double[] tableau, int nbElem, double borne) { int n = 0; for(int i = 0; i < nbElem; i++) if (tableau[i] > borne) n++; return n; } static int combien(char sexeVoulu, char [] sexe, int nbPers) { int n = 0; for(int i = 0; i < nbPers; i++) if (sexe[i] == sexeVoulu) n++; return n; } static void afficher(double [] taille, double[] poids, char [] sexe, int nbPers) { System.out.printf("Contenu des 3 tableaux :\n\n"); System.out.printf("indice taille poids sexe\n"); for(int i = 0; i < nbPers; i++) System.out.printf("%3d %8.2f %7.1f %5c\n", i, taille[i], poids[i], sexe[i]) ; System.out.printf("\n\n") ; } public static void main(String[] args) { final double BORNE1 = 1.75, BORNE2 = 60.0; double [] taille = {1.72, 1.86, 1.58, 1.76, 1.70}, poids = { 65.4, 76.1, 59.9, 73.4, 81.5}; char [] sexe = { 'F', 'M', 'F', 'F', 'M'} ; int nbPers = taille.length; afficher(taille, poids, sexe, nbPers); System.out.printf("Le nombre de personnes dont :\n"); System.out.printf(" - la taille depasse %.2f metre est %d\n", BORNE1, nombre(taille, nbPers, BORNE1)); System.out.printf(" - le poids depasse %.2f kg est %d\n", BORNE2, nombre(poids, nbPers, BORNE2)); System.out.printf("Le nombre de femmes : %d\n", combien('F', sexe, nbPers)) ; System.out.printf("Le nb. d'hommes : %d\n", combien('M', sexe, nbPers)); System.out.printf("La taille moyen : %.2f metre\n", moyenne(taille,nbPers)) ; System.out.printf("Le poids moyen : %.1f kg\n", moyenne(poids, nbPers)); } } /* Exécution : --------------------Configuration: -------------------- Contenu des 3 tableaux : indice taille poids sexe 0 1,72 65,4 F 1 1,86 76,1 M 2 1,58 59,9 F 3 1,76 73,4 F 4 1,70 81,5 M Le nombre de personnes dont : - la taille depasse 1,75 metre est 2 - le poids depasse 60,00 kg est 4 Le nombre de femmes : 3 Le nb. d'hommes : 2 La taille moyen : 1,72 metre Le poids moyen : 71,3 kg Process completed. */