freddye
unread,Apr 2, 2022, 2:07:14 PM4/2/22You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Bonjour,
J'ai créé une class Matrice me permettant de calculer la transposé d'une
matrice. Mais lors de l'affichage ça ne se passe pas comme prévu...
Voilà ma classe :
public class Matrice {
private int[][] coeff = null;
public Matrice(int i, int j)
{
this.setLength(i,j);
}
public Matrice()
{
this(0,0);
}
public Matrice(int[][] mat)
{
this.coeff = mat;
}
// définit une matrice de type int[][]
public void setMatrice(int[][] mat)
{
this.coeff = mat;
}
// définit une valeur à la position i et j
// i - ligne
// j - col
public void setValue(int i, int j, int value)
{
this.coeff[i][j] = value;
}
// on définit la taille de la mtrice
public void setLength(int i, int j)
{
this.coeff = new int[i][j];
}
public int[][] getMatrice()
{
return this.coeff;
}
// retourne le nombre de ligne
public int getRows()
{
return this.coeff.length;
}
// retourne le nombre de colonne
public int getColumns()
{
return this.coeff[0].length;
}
// retourne la valeur à la position i et j
public int getValue(int i, int j)
{
return this.coeff[i][j];
}
// transpose la matrice
public Matrice getMatriceTranspose()
{
Matrice a = new Matrice(this.getColumns(), this.getRows());
int tmp = 0;
for (int i=0; i<a.getRows(); i++)
for (int j=0; j<a.getColumns(); j++)
{
tmp = this.getValue(j,i);
a.setValue(i,j,tmp);
}
return a;
}
public static void main(String[] args) {
Matrice a = new Matrice();
a.setMatrice(new int[][] {{1,2},{3,4}});
System.out.println("Matrice inverse : n"+ a.getMatriceTranspose());
}
}
Et en sortie j'obtiens ceci :
Matrice inverse :
calculMat.Matrice@2aae9190
J'espère que quelqu'un pourra m'éclairer...
Merci d'avance.