questa è la classe matrice rifatta:
codice:
package matrici;
public class matrice {
int righe, colonne;
int[][] valori;
static final int DIMR = 50;
static final int DIMC = 50;
public matrice(int righe, int colonne) {
this.colonne = colonne;
this.righe = righe;
this.valori = new int[DIMC][DIMR];
}
public int getColonne() {
return colonne;
}
public int getRighe() {
return righe;
}
public String isQuadrata() {
if (this.valori[righe] != this.valori[colonne]) {
return "matrice rettangolare";
} else {
return "matrice quadrata";
}
}
public void setValore(int val, int righe, int colonne) {
valori[righe][colonne] = val;
}
public int getValore(int righe, int colonne) {
return valori[righe][colonne];
}
public String isTrasposta() {
if (this.valori[righe][colonne] == this.valori[colonne][righe]) {
return "matrice trasposta";
} else {
return "matrice non trasposta";
}
}
public String isNulla() {
if (this.valori[righe][colonne] == 0) {
return "matrice nulla";
} else {
return "matrice non nulla";
}
}
public void getSomma(matrice m) {
if (this.valori[righe] == m.valori[righe] && this.valori[colonne] == m.valori[colonne]) {
for (int i = 0; i < righe; i++) {
for (int j = 0; j < colonne; j++) {
this.valori[i][j] += m.valori[i][j];
}
}
} else {
System.err.println("non si puo sommare");
}
}
public String isInversa() {
if ((this.valori[righe][colonne]) * ((this.valori[righe][colonne]) - 1) == 1) {
return "matrice inversa";
} else {
return "matrice non inversa";
}
}
public String isSimmetrica() {
if (isTrasposta().equalsIgnoreCase("matrice trasposta")) {
return "matrice simmetrica";
} else {
return "matrice non simmetrica";
}
}
public String isIndentita() {
if (this.valori[righe] == this.valori[colonne] && this.valori[righe][colonne] == 1) {
return "matrice indentita";
} else {
return "matrice non indentita";
}
}
public String isDiagonale() {
if (this.valori[righe] == this.valori[colonne] && this.valori[righe][colonne] == 0) {
return "matrice diagonale";
} else {
return "matrice non diagonale";
}
}
public String istriangolareSuperiore() {
String s="";
if (this.valori[righe] != this.valori[colonne]) {
for (int i = 1; i < righe; i++) {
for (int j = 1; j < righe; j++) {
if (this.valori[righe][colonne] == this.valori[i][j]) {
s = "matrice triangolare inferiore";
} else {
for (int k = 1; k < righe; k--) {
for (int l = 1; l < righe; l--) {
if (this.valori[righe][colonne] == this.valori[k][l]) {
s = "matrice triangolare superiore";
} else {
s = "matrice non triangolare";
}
}
}
}
}
}
} else {
System.err.println("ci troviamo nella diagolnale");
}
return s;
}
}