Completati esercizi matrici per 25-1-23

Completati esercizi Identità, Riempimento e Simmetria tra matrici + PDF
This commit is contained in:
2023-01-22 22:38:35 +01:00
parent da24fc76ae
commit c4e9db119c
6 changed files with 88 additions and 0 deletions

30
Matrici/Identita.java Normal file
View File

@@ -0,0 +1,30 @@
public class Identita {
public static void main(String[] args) {
int[][] matrice =
{
{1, 0, 0, 0, 0},
{0, 1, 0, 0, 0},
{0, 0, 1, 0, 0},
{0, 0, 0, 1, 0},
{0, 0, 0, 0, 1}
};
System.out.println(cercaIdentita(matrice));
}
private static boolean cercaIdentita(int[][] matrice) {
for (int i = 0; i < matrice.length; i++) {
for (int j = 0; j < matrice[0].length; j++) {
if(matrice[i][i] != 1) {
return false;
}
if(i != j && matrice[i][j] != 0) {
return false;
}
}
}
return true;
}
}