Cambiar de lugar componentes matriz
Publicado por Pepe (1 intervención) el 28/11/2018 19:06:34
Hola, tengo este metodo para crear una matriz de numeros aleatorios y que el mayor de ellos se transforme en un espacio en blanco, como puedo cambiar ese espacio en blanco por el numero de la izquierda? gracias
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package matrix;
public class Matrix {
static int n;
public static int[][] readMatrix(int rows, int cols){
if ((rows <= 0) || (cols <= 0))
return null;
int[][] m = new int[rows][cols];
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++) {
n = (int) (Math.random()*cols*rows+1);
while (nrep(m, rows, cols, n) == false) {
n = (int) (Math.random()*cols*rows+1);
}
m[i][j] = n;
}
return m;
}
public static boolean nrep(int m[][], int rows, int cols, int n) {
for (int i = 0; i < rows; i++)
for (int j = 0; j < cols; j++) {
if (n == m[i][j])
return false;
}
return true;
}
public static void printmatrix(int m[][], int a) {
for (int i = 0; i < m.length; i++) {
for (int j = 0; j < m[i].length; j++) {
if (m[i][j] < 10) {
if (m[i][j] == a*a)
System.out.print(" "+ " " +" " + " ");
else
System.out.print(" "+ " " +m[i][j] + " ");
}
else
if (m[i][j] >= 100) {
if (m[i][j] == a*a)
System.out.print(" "+ " " +" " + " ");
else
System.out.print(m[i][j]+ " ");
}
else
if (m[i][j] == a*a && a*a >=10 && a*a <100)
System.out.print(" "+ " " +" " + " ");
else
System.out.print(" " +m[i][j] +" ");
}
System.out.println();
}
}
}
System.out.println();
}
}
}
Valora esta pregunta
0