/* Recherche de la valeur minimale */ /* d'un tableau d'entiers */ /* sans organisation particuliere */ /* Parcours sequentiel */ public class RechercheMinimum { /////////////////////////////////////////////////// /* Fonction de recherche et retour de la valeur */ /* minimale contenue dans un tableau de int */ /* sans organisation particuliere */ /* Methode sequentielle */ /* t : Le tableau d'entiers de recherche */ /* (au moins une valeur) */ static int valeurMinimale(int [] t) { int min = t[0]; for ( int i = 1 ; i < t.length ; i++ ) { if ( t[i] < min ) { min = t[i]; } } return min; } /////////////////////////////////////////////////// /* Fonction d'affichage des valeurs contenues */ /* dans un tableau de int */ static void affichageTableau(int [] t) { for ( int i = 0 ; i < t.length ; i++ ) { Ecran.formater("%4d",t[i]); } } /* Fonction de creation d'un tableau de 10 int */ /* initialise avec des valeurs tirees au sort */ /* entre 0 et 1000 inclus */ static int [] initRand() { int [] t = new int[10]; for ( int i = 0 ; i < t.length ; i++ ) { t[i] =(int) (Math.random()*1001.0); } return t; } /* Programme principal */ public static void main(String [] args) { int min; int [] t; t = initRand(); affichageTableau(t); Ecran.sautDeLigne(); min = valeurMinimale(t); Ecran.afficherln("Valeur minimale : ",min); } }