/* Tests d'egalite entre 2 tableaux */ public class TestEgaliteTableaux { ////////////////////////////////////////////////// /* Programme principal */ public static void main(String [] args) { boolean egal; int i; /* Declaration et initialisation de trois */ /* tableaux: t1, t2 et t3 */ int [] t1 = { 0,1,2,3 }; int [] t2 = { 0,0,0,0 }; int [] t3 = { 0,1,2,3 }; /* Affichage du contenu des trois tableaux */ Ecran.afficher("t1 : "); for ( i = 0 ; i < t1.length ; i = i+1 ) { Ecran.afficher(t1[i]," "); } Ecran.sautDeLigne(); Ecran.afficher("t2 : "); for ( i = 0 ; i < t2.length ; i = i+1 ) { Ecran.afficher(t2[i]," "); } Ecran.sautDeLigne(); Ecran.afficher("t3 : "); for ( i = 0 ; i < t3.length ; i = i+1 ) { Ecran.afficher(t3[i]," "); } Ecran.sautDeLigne(); /* Tests d'egalite par utilisation du == */ egal = (t1 == t2); Ecran.afficherln("Test d'egalite avec == entre t1 et t2 : ",egal); egal = (t1 == t3); Ecran.afficherln("Test d'egalite avec == entre t1 et t3 : ",egal); /* Tests d'egalite par implantation */ /* du test composante par composante */ egal = true; if ( t1.length != t2.length ) { egal = false; } else { i = 0; while ( ( egal == true ) && ( i < t1.length ) ) { if ( t1[i] != t2[i] ) { egal = false; } i = i+1; } } Ecran.afficherln("Test d'egalite sur composantes entre t1 et t2 : ",egal); egal = true; if ( t1.length != t3.length ) { egal = false; } else { i = 0; while ( ( egal == true ) && ( i < t1.length ) ) { if ( t1[i] != t3[i] ) { egal = false; } i = i+1; } } Ecran.afficherln("Test d'egalite sur composantes entre t1 et t3 : ",egal); /* Affichage des adresses mémoire */ /* des trois tableaux */ Ecran.afficherln("t1 : ",t1); Ecran.afficherln("t2 : ",t2); Ecran.afficherln("t3 : ",t3); } ////////////////////////////////////////////////// }