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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| public class ExempleMatrice {
public static void main(String[] args) {
System.out.println("Cas matrices de mêmes tailles");
memesTailles();
System.out.println("Cas matrice 1 plus petite");
mat1PlusPetite();
System.out.println("Cas matrice 2 plus petite");
mat2PlusPetite();
System.out.println("Cas de ton exemple");
casExemple();
}
private static void casExemple() {
Matrice mat1 = new Matrice(new char[][]{
{'1', '0', '0', '0', '1', '0', '1', '1'},
{'1', '0', '0', '1', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '1', '0', '1'},
{'1', '0', '0', '0', '0', '1', '0', '0'}});
Matrice mat2 = new Matrice(new char[][]{
{'1', '0', '0', '1', '0', '0', '0', '0'},
{'1', '0', '0', '0', '1', '0', '1', '1'},
{'1', '0', '0', '0', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '1', '1', '1'},
{'1', '0', '0', '0', '0', '1', '0', '0'}});
diffEtModif(mat1,mat2);
}
private static void memesTailles() {
Matrice mat1 = new Matrice(new char[][]{
{'1', '0', '0', '0', '1', '0', '1', '1'},
{'1', '0', '0', '1', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '1', '0', '1'},
{'1', '0', '0', '0', '0', '1', '0', '0'}});
Matrice mat2 = new Matrice(new char[][]{
{'1', '0', '0', '1', '0', '0', '0', '0'},
{'1', '0', '0', '0', '1', '0', '1', '1'},
{'1', '0', '0', '0', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '1', '1', '1'}});
diffEtModif(mat1,mat2);
}
private static void mat1PlusPetite() {
Matrice mat1 = new Matrice(new char[][]{
{'1', '0', '0', '0', '1', '0', '1'},
{'1', '0', '0', '1', '1', '0', '0'},
{'1', '0', '0', '1', '1', '0', '0'},
{'1', '0', '0', '1', '1', '1', '0'}});
Matrice mat2 = new Matrice(new char[][]{
{'1', '0', '0', '1', '0', '0', '0', '0'},
{'1', '0', '0', '0', '1', '0', '1', '1'},
{'1', '0', '0', '0', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '1', '1', '1'}});
diffEtModif(mat1,mat2);
}
private static void mat2PlusPetite() {
Matrice mat1 = new Matrice(new char[][]{
{'1', '0', '0', '0', '1', '0', '1', '1'},
{'1', '0', '0', '1', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '0', '0', '1'},
{'1', '0', '0', '1', '1', '1', '0', '1'},
{'1', '0', '0', '0', '0', '1', '0', '0'}});
Matrice mat2 = new Matrice(new char[][]{
{'1', '0', '0', '1', '0', '0', '0'},
{'1', '0', '0', '0', '1', '0', '1'},
{'1', '0', '0', '0', '1', '0', '0'},
{'1', '0', '0', '1', '1', '0', '0'}});
diffEtModif(mat1,mat2);
}
private static void diffEtModif(Matrice mat1, Matrice mat2) {
System.out.println("Matrice 1:");
System.out.println(mat1);
System.out.println("Matrice 2:");
System.out.println(mat2);
if ( mat1.equals(mat2) ) {
System.out.println("Pas de différences");
}
else {
List<Difference> differences = mat1.getDifferences(mat2);
System.out.println("Différences entre les matrices :");
for(Difference difference : differences) {
System.out.println(difference);
System.out.println();
}
mat2.redimensionne(mat1.getNbLignes(), mat2.getNbColonnes());
mat2.setData(mat1);
}
}
} |
Partager