Concetti Chiave
- The method "scambiaDiPostoDueRighe" swaps two specified rows in a matrix of integers.
- It takes a matrix M and two row indices R1 and R2 as input parameters.
- The method returns the same matrix after exchanging the contents of the two specified rows.
- A temporary container variable is used to facilitate the swapping of elements between the rows.
- The swapping process involves iterating only over the columns since the rows to be swapped are predetermined.
Tema 97
Scrivere un metodo scambiaDiPostoDueRighe che riceve una matrice di interi M e due numeri R1 e R2 e restituisce la stessa matrice dopo aver effettuato lo scambio tra le righe R1 ed R2.Ad esempio, sia M la matrice così costituita
3 | 18 | 15 | 7 | 2 |
1 | 9 | 11 | 4 | 6 |
7 | 2 | 6 | 3 | 5 |
5 | 1 | 25 | 2 | 1 |
3 | 2 | 33 | 4 | 4 |
3 | 18 | 15 | 7 | 2 |
5 | 1 | 25 | 2 | 1 |
7 | 2 | 6 | 3 | 5 |
1 | 9 | 11 | 4 | 6 |
3 | 2 | 33 | 4 | 4 |
public class tema97{ public static int[][] scambiaDiPostoDueRighe (int[][] M, int R1, int R2){ // approntiamo un contenitore che ci servirà per posizionare momentaneamente un // elemento da spostare int contenitoreTemporaneo; // facciamo partire un ciclo che interesserà soltanto le colonne visto che le // righe su cui lavorare sono note for (int j = 0; j