Concetti Chiave
- The method scambiaDiPostoDueColonne takes an integer matrix M and two column indices, C1 and C2, as input parameters.
- The function swaps the elements of columns C1 and C2 within the given matrix M.
- A temporary container is used to hold values during the swap process to ensure data integrity.
- The swapping operation is performed row by row, iterating through all the rows of the matrix.
- The example provided shows the transformation of matrix M after swapping columns 1 and 3.
Tema 98
Scrivere un metodo scambiaDiPostoDueColonne che riceve una matrice di interi M e due numeri C1 e C2 e restituisce la stessa matrice dopo aver effettuato lo scambio tra le colonne C1 ed C2.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 | 7 | 15 | 18 | 2 |
1 | 4 | 11 | 9 | 6 |
7 | 3 | 6 | 2 | 5 |
5 | 2 | 25 | 1 | 1 |
3 | 4 | 33 | 2 | 4 |
public class tema98{ public static int[][] scambiaDiPostoDueColonne (int[][] M, int C1, int C2){ // approntiamo un contenitore che ci servirà per posizionare momentaneamente un // elemento da spostare int contenitoreTemporaneo; // facciamo partire un ciclo che interesserà soltanto le righe visto che le // colonne su cui lavorare sono note for (int i = 0; i