Comment créer un type puis l'utiliser dans une méthode ?
Salut
Voila je cherche a creer une classe (un type) Matrix puis l'utiliser dans la methode d'une autre classe pourvez vous m'aider
voila ce que j'ai essayé de faire meis j'ai un probleme :
Code:
1 2 3 4 5 6
| public class Matrix {
private final int[][] data;
public Matrix(int[][] data) {
this.data = data;
} |
Code:
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
| public class testMatrice {
public Matrix[][] addMatrice(Matrix[][] mat1, Matrix[][] mat2) {
Matrix m1[][], m2[][];
Matrix[][] som = null;
m1 = new Matrix[mat1.length][mat1[0].length];
m2 = new Matrix[mat2.length][mat2[0].length];
m1 = mat1;
m2 = mat2;
som = new Matrix[m1.length][m1[0].length];
for (int i = 0; i < m1.length; i++)
for (int j = 0; j < m1[0].length; j++)
som[i][j] = m1[i][j] + m2[i][j];
return som;
}
} |
j'ai un probleme au niveau de la 18eme ligne cette ligne : m1[i][j] + m2[i][j]; est soulignée en rouge dans mon editeur eclipse et le message d'erreur est :
Code:
the operator "+" is undefined for the argument type Matrix
Cordialement