37 lines
1.1 KiB
Java
37 lines
1.1 KiB
Java
package capitulo04.bloque10;
|
|
|
|
/* En el ejercicio pone 20 filas y 10 columnas, pero el ejemplo son
|
|
* 10 filas y 20 columnas, yo lo he puesto como en el ejemplo.
|
|
*/
|
|
|
|
public class Ejercicio04 {
|
|
public static void main(String[] args) {
|
|
char[][] matriz = new char[10][20];
|
|
|
|
for (int i = 0; i < matriz.length; i++) {
|
|
for (int j = 0; j < matriz[i].length; j++) {
|
|
matriz[i][j] = ' ';
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < matriz.length; i++) {
|
|
matriz[i][0] = '*';
|
|
matriz[i][matriz[i].length - 1] = '*';
|
|
}
|
|
for (int j = 0; j < matriz[0].length; j++) {
|
|
matriz[0][j] = '*';
|
|
matriz[matriz.length - 1][j] = '*';
|
|
}
|
|
|
|
int filaAleatoria = (int) (Math.random() * (matriz.length - 2)) + 1;
|
|
int columnaAleatoria = (int) (Math.random() * (matriz[0].length - 2)) + 1;
|
|
matriz[filaAleatoria][columnaAleatoria] = '0';
|
|
|
|
for (int i = 0; i < matriz.length; i++) {
|
|
for (int j = 0; j < matriz[i].length; j++) {
|
|
System.out.print(matriz[i][j]);
|
|
}
|
|
System.out.println();
|
|
}
|
|
}
|
|
} |