-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpruebaAlberto.java
More file actions
79 lines (66 loc) · 2.9 KB
/
Copy pathpruebaAlberto.java
File metadata and controls
79 lines (66 loc) · 2.9 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import java.util.Random;
import java.util.Scanner;
public class pruebaAlbertov2 {
public static void main(String[] args) {
Random rdm = new Random();
Scanner sc = new Scanner(System.in);
int filas = 10;
int columnas = 10;
int[][] tableroNumeros = new int[filas][columnas];
String[][] tableroX = new String[filas][columnas];
// Inicializar los tableros
for (int i = 0; i < filas; i++) {
for (int j = 0; j < columnas; j++) {
tableroNumeros[i][j] = rdm.nextInt(89) + 10;
tableroX[i][j] = " ";
}
}
// Mostrar el tablero de números (opcional)
System.out.println("Tablero de números aleatorios:");
mostrarTablero(tableroNumeros);
// Permitir al usuario insertar 10 números
for (int i = 0; i < 10; i++) {
System.out.println(" ");
System.out.print("· Ingresa el número " + (i + 1) + ": ");
int num = sc.nextInt();
if (num >= 100 || num < 10) {
System.out.println("Ese número no es posible.");
} else {
marcarX(tableroNumeros, tableroX, num);
}
}
// Mostrar el tablero de resultados con las X
System.out.println(" ");
System.out.println("Tablero resultado con X marcando las respuestas correctas:");
mostrarTableroConResultados(tableroNumeros, tableroX);
}
private static void mostrarTablero(int[][] tablero) {
for (int i = 0; i < tablero.length; i++) { // Recorremos las filas
for (int j = 0; j < tablero[i].length; j++) { // Recorremos las columnas de cada fila
System.out.print(tablero[i][j] + " "); // Imprimimos el número con un espacio
}
System.out.println(); // Hacemos un salto de línea al final de cada fila
}
}
private static void mostrarTableroConResultados(int[][] tableroNumeros, String[][] tableroX) {
for (int i = 0; i < tableroNumeros.length; i++) {
for (int j = 0; j < tableroNumeros[i].length; j++) {
if (tableroX[i][j] == "XX") {
System.out.print("XX "); // Mostrar la X para respuestas correctas
} else {
System.out.print(tableroNumeros[i][j] + " "); // Mostrar el número original
}
}
System.out.println();
}
}
private static void marcarX(int[][] tableroNumeros, String[][] tableroX, int numero) {
for (int i = 0; i < tableroNumeros.length; i++) {
for (int j = 0; j < tableroNumeros[i].length; j++) {
if (tableroNumeros[i][j] == numero) { // Comprobar si el número coincide con el del tablero de numeros
tableroX[i][j] = String.valueOf("XX"); // Marcar XX si el número coincide
}
}
}
}
}