/* Initialisation de tableaux de reels */ public class InitialisationTableauReel { ///////////////////////////////////////////////// /* Fonction d'affichage d'un tableau de double */ /* tab : Le tableau de double a afficher */ static void affichage(double [] tab) { int i; for ( i = 0 ; i < tab.length ; i = i+1 ) { Ecran.formater("%6.3f",tab[i]); } Ecran.sautDeLigne(); } /* Fonction d'initialisation d'un tableau */ /* de double avec des 0.0 */ /* tab : Le tableau de double a initialiser */ static void initialisation(double [] tab) { int i; for ( i = 0 ; i < tab.length ; i = i+1 ) { tab[i] = 0.0; } } /* Fonction d'initialisation d'un tableau */ /* de double avec des reels tires au sort */ /* entre 0.0 et 1.0 */ /* tab : Le tableau de double a initialiser */ static void initRand(double [] tab) { int i; for ( i = 0 ; i < tab.length ; i = i+1 ) { tab[i] = Math.random(); } } /* Fonction d'initialisation d'un tableau */ /* de double avec une serie croissante */ /* de nombres aleatoires */ /* tab : Le tableau de double a initialiser */ static void initRandCroissant(double [] tab) { int i; tab[0] = Math.random(); for ( i = 1 ; i < tab.length ; i = i+1 ) { tab[i] = tab[i-1]+Math.random(); } } /* Programme principal */ public static void main(String [] args) { int i; double [] t1 = { 0.0,1.0,0.0,1.0,0.0 }; double [] t2 = new double[6]; double [] t3 = new double[6]; /* Test de la fonction d'initialisation a 0.0 */ Ecran.afficherln("Un tableau de 5 réels avant"); Ecran.afficherln("et après initialisation à 0.0"); affichage(t1); initialisation(t1); affichage(t1); Ecran.sautDeLigne(); /* Test de la fonction d'initialisation avec */ /* des nombres aleatoires entre 0.0 et 1.0 */ Ecran.afficherln("Un tableau de 6 réels avant et après"); Ecran.afficherln("initialisation avec des nombres aléatoires"); affichage(t2); initRand(t2); affichage(t2); Ecran.sautDeLigne(); /* Test de la fonction de creation d'une serie */ /* croissante de nombres aleatoires */ Ecran.afficherln("Un tableau de 6 réels avant et après initialisation"); Ecran.afficherln("avec une série croissante de nombres aléatoires"); affichage(t3); initRandCroissant(t3); affichage(t3); } ///////////////////////////////////////////////// }