/* Sous-algorithme d'affichage d'un tableau */ /* de double */ /* Sous-algorithmes d'initialisation */ /* et de generation d'un tableau de double */ /* tirés au sort */ /* Utilisation de ces sous-algorithmes */ public class FonctionsGenerationTableau { /* Fonction d'affichage d'un tableau de double */ /* tab : Le tableau à afficher */ static void affichage(double [] tab) { int i; for ( i = 0 ; i < tab.length ; i = i+1 ) { Ecran.afficherln(tab[i]); } } /* Fonction d'initialisation d'un tableau */ /* de double avec des nombres tirés au sort */ /* dans l'intervalle [0.0,max[ */ /* max : La borne supérieure de l'intervalle */ /* tab : Le tableau à initialiser */ static void initialisationRand(double [] tab,double max) { int i; for ( i = 0 ; i < tab.length ; i = i+1 ) { tab[i] = Math.random()*max; } } /* Fonction de génération et retour */ /* d'un tableau de double avec des nombres */ /* tirés au sort dans l'intervalle [0.0,max[ */ /* n : La taille du tableau généré */ /* max : La borne supérieure de l'intervalle */ static double [] generationRand(int n,double max) { double [] tab = new double[n]; initialisationRand(tab,max); return tab; } /* Programme principal */ public static void main(String [] args) { int n; double limite; double [] t; Ecran.afficher("SVP, taille du tableau? "); n = Clavier.saisirInt(); Ecran.afficher("SVP, valeur limite? "); limite = Clavier.saisirDouble(); t = generationRand(n,limite); affichage(t); } }