Concetti Chiave
- The method verificaSeEsisteSequenzaInMatrice checks for a sequence of numbers from 1 to n within a matrix of integers M.
- If the sequence is found within the matrix, the method returns TRUE; otherwise, it returns FALSE.
- The example matrix provided demonstrates a sequence check for numbers 1 through 7, where the sequence is present.
- The method utilizes a boolean variable 'trovato' to facilitate the verification process.
- The method initiates a loop starting from 1 up to a parameter value 'k' to perform the sequence check.
Tema 60
Scrivere un metodo verificaSeEsisteSequenzaInMatrice che riceve una matrice di interi M e un intero n, e restituisce TRUE se all’interno di M esiste una sequenza di numeri da 1 fino a n; FALSE altrimenti.Ad esempio, sia M la matrice così costituita
3 | 18 | 15 | 7 | 2 |
1 | 9 | 11 | 4 | 6 |
7 | 8 | 6 | 9 | 5 |
5 | 1 | 25 | 2 | 1 |
8 | 2 | 33 | 4 | 9 |
public class tema60{ public static boolean verificaSeEsisteSequenzaInMatrice (int[][] M, int n){ // prepariamo una variabile boolean che useremo durante la verifica boolean trovato; // avviamo un ciclo che parte da 1 e arriva fino al valore k acquisito dal // metodo come parametro for(int k = 1; k