-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathComputer.java
More file actions
31 lines (26 loc) · 902 Bytes
/
Copy pathComputer.java
File metadata and controls
31 lines (26 loc) · 902 Bytes
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
package baseball.Model;
import camp.nextstep.edu.missionutils.Randoms;
public class Computer {
public static int[] getComputerNum(int size, int start, int end) {
int[] numbers = new int[3];
for (int i = 0; i < size; i++) {
numbers[i] = RandomNumber(numbers, start, end, i);
}
return numbers;
}
private static int RandomNumber(int[] numbers, int start, int end, int i) {
int randomNumber = Randoms.pickNumberInRange(start, end);
while (!isSame(numbers, i, randomNumber)) {
randomNumber = Randoms.pickNumberInRange(start, end);
}
return randomNumber;
}
private static Boolean isSame(int[] numbers, int i, int randomNumber) {
for (int j = 0; j < i; j++) {
if (numbers[j] == randomNumber) {
return false;
}
}
return true;
}
}