/* Tri a bulle d'un tableau d'entiers */ public class TriBulle { /* Methode d'affichage des valeurs contenues */ /* dans un tableau de int */ static void affichageTableau(int [] t) { int i; for ( i = 0 ; i < t.length ; i = i+1 ) { Ecran.afficher(t[i]," "); } Ecran.sautDeLigne(); } /* Methode 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]; int i; for ( i = 0 ; i < t.length ; i = i+1 ) { t[i] =(int) (Math.random()*1001.0); } return t; } /////////////////////////////////////////////////// /* Methode de tri a bulle d'un tableau d'entiers */ static void triBulle(int [] t) { int i; int j; int aux; for ( i = 0 ; i < t.length-1 ; i = i+1 ) { for ( j = 0 ; j < t.length-i-1 ; j = j+1 ) { if ( t[j] > t[j+1] ) { aux = t[j]; t[j] = t[j+1]; t[j+1] = aux; } } } } /////////////////////////////////////////////////// /* Programme principal */ public static void main(String [] args) { int [] t; t = initRand(); affichageTableau(t); triBulle(t); affichageTableau(t); } }