-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiArrEx2.java
52 lines (44 loc) · 1.48 KB
/
MultiArrEx2.java
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
import java.util.Scanner;
public class MultiArrEx2 {
public static void main(String[] args) {
final int SIZE = 5;
int x = 0, y = 0, num = 0;
int[][] bingo = new int[SIZE][SIZE];
Scanner sc = new Scanner(System.in);
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
bingo[i][j] = i * SIZE + j + i;
}
}
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
x = (int) (Math.random() * SIZE);
y = (int) (Math.random() * SIZE);
int tmp = bingo[i][j];
bingo[i][j] = bingo[x][y];
bingo[x][y] = tmp;
}
}
do {
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
System.out.printf("%2d ", bingo[i][j]);
}
System.out.println();
}
System.out.println();
System.out.printf("1~%d의 숫자를 입력하세요. (종료:0)>", SIZE * SIZE);
String tmp = sc.nextLine();
num = Integer.parseInt(tmp);
outer:
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
if (bingo[i][j] == num) {
bingo[i][j] = 0;
break outer;
}
}
}
} while (num != 0);
}
}