-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixScambia.java
More file actions
41 lines (36 loc) · 1003 Bytes
/
Copy pathMatrixScambia.java
File metadata and controls
41 lines (36 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package Array;
public class MatrixScambia {
public static void main(String[] args) {
char[][] a = {{'a','b','c','d'},
{'e','f','g','h'},
{'i','j','k','l'}};
char [][] b = {{'m','n','o','p'},
{'q','r','s','t'},
{'u','v','x','y'}};
int[] c = {0,2};
stampa(a);
stampa(b);
scambia(a, b, c);
stampa(a);
stampa(b);
}
public static void scambia(char[][] a, char[][] b, int[] c) {
char temp;
for(int j = 0; j < c.length; j++){
for(int i = 0; i < a.length; i++){
temp = a[i][c[j]];
a[i][c[j]] = b[i][c[j]];
b[i][c[j]] = temp;
}
}
}
static void stampa(char[][] a) {
System.out.println("----------------------------------");
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
System.out.print(a[i][j]+ " ");
}
System.out.println();
}
}
}