diff --git a/Matrici/Identita.java b/Matrici/Identita.java new file mode 100644 index 0000000..76e3785 --- /dev/null +++ b/Matrici/Identita.java @@ -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; + } +} diff --git a/Matrici/Identita.pdf b/Matrici/Identita.pdf new file mode 100644 index 0000000..3576d50 Binary files /dev/null and b/Matrici/Identita.pdf differ diff --git a/Matrici/Riempimento.java b/Matrici/Riempimento.java new file mode 100644 index 0000000..14e596a --- /dev/null +++ b/Matrici/Riempimento.java @@ -0,0 +1,26 @@ +import java.util.Random; + +public class Riempimento { + public static void main(String[] args) { + int[][] matrice = new int[5][5]; + + riempiRandom(matrice, 100); + + for (int[] array : matrice) { + for(int num : array) { + System.out.printf("%2d ", num); + } + System.out.println(); + } + } + + public static void riempiRandom(int[][] matrice, int maxValue) { + Random generator = new Random(); + + for (int i = 0; i < matrice.length; i++) { + for (int j = 0; j < matrice[0].length; j++) { + matrice[i][j] = generator.nextInt(maxValue); + } + } + } +} diff --git a/Matrici/Riempimento.pdf b/Matrici/Riempimento.pdf new file mode 100644 index 0000000..968d304 Binary files /dev/null and b/Matrici/Riempimento.pdf differ diff --git a/Matrici/Simmetria.java b/Matrici/Simmetria.java new file mode 100644 index 0000000..d2c73bc --- /dev/null +++ b/Matrici/Simmetria.java @@ -0,0 +1,32 @@ +public class Simmetria { + public static void main(String[] args) { + int[][] matrice = + { + {1, 2, 3, 4, 5}, + {2, 1, 4, 5, 6}, + {3, 4, 1, 6, 7}, + {4, 5, 6, 1, 8}, + {5, 6, 7, 8, 1} + }; + + for (int[] array : matrice) { + for(int num : array) { + System.out.printf("%2d ", num); + } + System.out.println(); + } + + boolean simmetrico = true; + for (int i = 0; i < matrice.length; i++) { + for (int j = 0; j < matrice[0].length; j++) { + if (matrice[i][j] != matrice[j][i]) simmetrico = false; + } + } + + if(simmetrico) { + System.out.println("La matrice è simmetrica rispetto alla diagonale principale"); + } else { + System.out.println("La matrice non è simmetrica"); + } + } +} diff --git a/Matrici/Simmetria.pdf b/Matrici/Simmetria.pdf new file mode 100644 index 0000000..50e8689 Binary files /dev/null and b/Matrici/Simmetria.pdf differ