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
| public class Matrice
{
int [][] mat;
private int taille;
public Matrice(int taille)
{
if(taille > 0)
mat = new int[taille][taille];
}
public void multiplie(int n)
{
for(int i=0;i<mat.length;i++)
{
for(int j=0;j<mat[i].length;j++)
mat[i][j] *= n;
}
}
public void somme(int [][] mat2) // Matrice est une classe est pas un Type. Hors j'ai l'impression que tu l'utilises comme tel.
{
if (mat2.length==mat.length); //Attention a ne pas confondre l'affectation d'un test.
{
for(int i=0;i<mat.length;i++)
{
for(int j=0;j<mat[i].length;j++)
mat[i][j] += mat2[i][j];
}
}
}
public void affiche()
{
for(int i=0;i<mat.length;i++)
{
for(int j=0;j<mat[i].length;i++)
System.out.print(mat[i][j]+" ");
System.out.println();
}
}
} |