Sujet : problème d'affichage avec des calculs de matrice
De : nospam_ninonlois33 (at) *nospam* gmail.com.invalid (freddye)
Groupes : fr.comp.lang.javaDate : 02. Apr 2022, 19:16:52
Autres entêtes
Organisation : !No_Organization!
Message-ID : <QqGdnSnMyKKJDtX_nZ2dnUU7_8zNnZ2d@giganews.com>
Bonjour,
Vous pourrez retrouver ci-dessous une classe Matrice qui me permet de calculer
la transposé d'une matrice. Mais la sortie n'est pas celle attendu...
Voici mon code :
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 j'obtiens la sortie suivante :
Matrice inverse :
calculMat.Matrice@2aae9190J'espère que quelqu'un pourra m'éclairer...
Merci d'avance.