-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBingo.java
More file actions
59 lines (51 loc) · 1.8 KB
/
Copy pathBingo.java
File metadata and controls
59 lines (51 loc) · 1.8 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
import java.util.Random;
public class Bingo {
public static void main(String[] args) {
int[][] bingoCard = generateBingoCard();
printBingoCard(bingoCard);
}
public static int[][] generateBingoCard() {
int[][] card = new int[5][5];
Random rand = new Random();
// Llenar las columnas B, I, N, G, O
for (int i = 0; i < 5; i++) {
int start = i * 15 + 1; // Empieza en 1, 16, 31, 46, 61
int end = start + 14; // Termina en 15, 30, 45, 60, 75
fillColumn(card, i, start, end, rand);
}
// Espacio libre en el centro (columna N, fila 3)
card[2][2] = 0; // Espacio libre
return card;
}
public static void fillColumn(int[][] card, int column, int start, int end, Random rand) {
boolean[] used = new boolean[15];
for (int row = 0; row < 5; row++) {
if (column == 2 && row == 2) {
continue; // Saltar el espacio libre
}
int num;
do {
num = rand.nextInt(end - start + 1) + start;
} while (used[num - start]);
card[row][column] = num;
used[num - start] = true;
}
}
public static void printBingoCard(int[][] card) {
String[] headers = {" B ", " I ", " N ", " G ", " O "};
for (String header : headers) {
System.out.print(header);
}
System.out.println();
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 5; col++) {
if (card[row][col] == 0) {
System.out.print(" * "); // Espacio libre
} else {
System.out.printf("%2d ", card[row][col]);
}
}
System.out.println();
}
}
}