/* Fichier Ex1_H13.java Exemple 1 de révision du Java vu dans IFT 1810, tapé en classe le 23 janvier 2013 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + IFT 1170 A, TP # x + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Auteur(s) : Laliberté Pierre + + Bolduc, Jacinthe + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Ce programme, écrit en JAVA, permet de ... + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + Dernière mise à jour : + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ public class Ex1_H13 { static void afficher(char[] sexe, double[] taille, double[] poids, int nbPers) { System.out.printf("Contenu des 3 tableaux :\n"); for(int i = 0; i < nbPers ; i++) System.out.printf("%3d) %6c %7.2f %8.1f\n", i, sexe[i], taille[i], poids[i]); System.out.printf("\n\n"); } static int nombre(char sexeVoulu, char[] sexe, int nbPers) { int n = 0; for(int i = 0; i < nbPers; i++) if (sexe[i] == sexeVoulu) n++; return n; } static double maximum(char sexeVoulu, char[] sexe, int nbPers, double[] tableau) { double maxi = Double.MIN_VALUE; for (int i = 0; i < nbPers; i++) if (sexe[i] == sexeVoulu && tableau[i] > maxi) maxi = tableau[i] ; return maxi; } public static void main(String[] args) { char[] sexe = { 'F', 'M', 'F', 'F', 'M' }; double[] taille = { 1.75, 1.63, 1.61, 1.80, 1.84 }, poids = { 65.1, 72.3, 56.8, 67.2, 50.3 }; int nbPers = taille.length ; afficher(sexe, taille, poids, nbPers); int nbFem = Ex1_H13.nombre('F', sexe, nbPers), nbHom = Ex1_H13.nombre('M', sexe, nbPers); System.out.printf("Le nombre de femmes traitées : %d\n", nbFem ); System.out.printf("Le nombre d'hommes traité s : %d\n", nbHom); if (nbFem > 0) System.out.printf("La taille maximale des femmes : %.2f metre\n", maximum('F', sexe, nbPers, taille)); else System.out.printf("Aucune femme => pas de statistique\n"); if (nbHom > 0) System.out.printf("Le poids maximal des hommes : %.2f kg\n", maximum('M', sexe, nbPers, poids)); else System.out.printf("Aucun homme => pas de statistique\n"); } } /* Compilation et Exécution: --------------------Configuration: -------------------- Contenu des 3 tableaux : 0) F 1,75 65,1 1) M 1,63 72,3 2) F 1,61 56,8 3) F 1,80 67,2 4) M 1,84 50,3 Le nombre de femmes traitées : 3 Le nombre d'hommes traité s : 2 La taille maximale des femmes : 1,80 metre Le poids maximal des hommes : 72,30 kg Process completed. */