-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathComputer.java
More file actions
64 lines (55 loc) · 2.03 KB
/
Computer.java
File metadata and controls
64 lines (55 loc) · 2.03 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
import java.util.Random;
public class Computer {
public static int[] Create(){
Random random = new Random();
int numBoundary =0;
int[] _computerNum = new int[3];
while(numBoundary<3){
if(numBoundary==0){
_computerNum[numBoundary]=random.nextInt(8)+1;
}
else{
_computerNum[numBoundary]=random.nextInt(8)+1;
if(numBoundary==1 && _computerNum[numBoundary]==_computerNum[numBoundary-1]) continue;
if(numBoundary==2 && _computerNum[numBoundary]==_computerNum[numBoundary-1] | _computerNum[numBoundary]==_computerNum[numBoundary-2]) continue;
}
numBoundary++;
}
return _computerNum;
}
public static int[] Check(int[] _userNum, int[] _computerNum){
int _strike =0;
int _ball = 0;
int[] _strikeAndBallArry = new int[2];
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
if (_computerNum[j] == _userNum[k]) {
if (j == k) {
_strike++;
} else {
_ball++;
}
break;
}
}
}
_strikeAndBallArry[0]=_ball;
_strikeAndBallArry[1]=_strike;
return _strikeAndBallArry;
}
public static int numBallAndStrike(int[] _strikeAndBallArry) {
if (_strikeAndBallArry[0] == 0 && _strikeAndBallArry[1] == 0) {
System.out.printf("낫싱");
} else if (_strikeAndBallArry[0] == 0) {
System.out.printf(_strikeAndBallArry[1] + "스트라이크 ");
} else if (_strikeAndBallArry[1] == 0) {
System.out.printf(_strikeAndBallArry[0] + "볼 ");
} else {
System.out.printf(_strikeAndBallArry[1] + "스트라이크 " + _strikeAndBallArry[0] + "볼");
}
if (_strikeAndBallArry[1] == 3) {
return _strikeAndBallArry[1];
}
return 0;
}
}