1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
public static void main(String[] args) {
String[] toto = { "a", "b", "c", "d", "e" };
String[] titi = { "c", "a", "b", "f" };
// on cherche ce qu'il n'y a que dans toto
for (int p = 0; p < toto.length; p++) {
int q;
for (q = 0; q < titi.length; q++) {
if (toto[p].equals(titi[q]))
break;
// doublon trouvé.
// on sort prématurément de la boucle ; q < titi.length
}
if (q== titi.length ) {
// on a parcouru tout titi sans trouver toto[p]
System.out.println("'" + toto[p] + "' n'existe que dans toto");
}
}
// on cherche ce qu'il n'y a que dans titi
for (int p = 0; p < titi.length; p++) {
int q;
for (q = 0; q < toto.length; q++) {
if (titi[p].equals(toto[q]))
break;
// doublon trouvé.
// on sort prématurément de la boucle ; q < toto.length
}
if (q== toto.length) {
// on a parcouru tout toto sans trouver titi[p]
System.out.println("'" + titi[p] + "' n'existe que dans titi");
}
}
} |