/* Tests d'affectation entre tableaux */ public class AffectationEntreTableaux { ////////////////////////////////////////////////// /* Programme principal */ public static void main(String [] args) { int i; /* Declaration et initialisation de deux */ /* tableaux: t1 et t2 */ int [] t1 = { 0,1,2,3 }; int [] t2 = { 0,0,0,0 }; /* Affichage du contenu des deux tableaux */ Ecran.afficherln("Tableaux t1 et t2 initiaux"); 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(); /* Copie du contenu de t1 dans t2 puis */ /* réaffichage du contenu des deux tableaux */ Ecran.afficherln("t1 et t2 après copie de t1 dans t2"); for ( i = 0 ; i < t1.length ; i = i+1 ) { t2[i] = t1[i]; } 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(); /* Remplissage de t1 avec des 0 puis */ /* réaffichage du contenu des deux tableaux */ Ecran.afficherln("t1 et t2 après remplissage de t1 avec des 0.0"); t1[0] = 0; t1[1] = 0; t1[2] = 0; t1[3] = 0; 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(); /* Affichage des adresses mémoire */ /* de t1 et de t2 */ Ecran.afficherln("Adresses mémoire de t1 et t2"); Ecran.afficherln("t1 : ",t1); Ecran.afficherln("t2 : ",t2); /* Affectation de t1 avec t2 puis */ /* réaffichage du contenu des deux tableaux */ Ecran.afficherln("t1 et t2 après affectation de t1 avec t2 (=)"); t1 = t2; 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(); /* Réaffichage des adresses mémoire */ /* de t1 et de t2 */ Ecran.afficherln("Adresses mémoire de t1 et t2"); Ecran.afficherln("t1 : ",t1); Ecran.afficherln("t2 : ",t2); /* Remplissage de t1 avec des 0 puis */ /* réaffichage du contenu des deux tableaux */ Ecran.afficherln("t1 et t2 après remplissage de t1 avec des 0"); t1[0] = 0; t1[1] = 0; t1[2] = 0; t1[3] = 0; 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(); /* Remplissage de t2 avec des 1 puis */ /* réaffichage du contenu des deux tableaux */ Ecran.afficherln("t1 et t2 après remplissage de t2 avec des 1"); t2[0] = 1; t2[1] = 1; t2[2] = 1; t2[3] = 1; 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(); } ////////////////////////////////////////////////// }