import java.util.Random;
import java.util.Scanner;
public class Q3 {
static void makeRandom(int[] com,Random r) {
for(int i = 0;i<com.length;i++) {
com[i] = r.nextInt(9)+1;
for(int j =0;j<i;j++) {
if(com[i] == com[j]) {
i--;
break;
}
}
}
System.out.println(com[0]+","+com[1]+","+com[2]);
}
static int[] userInput() {
Scanner sc = new Scanner(System.in);
int[] user = new int[3];
for(int i = 0;i<user.length;i++) {
System.out.print((i+1)+"번째 숫자 : ");
user[i] = sc.nextInt();
//범위 1~9아닌경우
if(user[i]<1 || user[i] > 9) {
System.out.println("잘못된 입력입니다.");
i--;
continue;
}
for(int j = 0;j<i;j++) {
if(user[i] == user[j]) {
System.out.println("잘못된 입력입니다.");
i--;
break;
}
}
}
return user;
}
static int[] strikeBallCheck(int[] user, int[] com) {
int[] result = new int[2];
for(int i = 0;i<user.length;i++) {
for(int j = 0;j<com.length;j++) {
if(user[i] == com[j]) {
if(i == j) {
result[0]++;
}
else {
result[1]++;
}
}
}
}
return result;
}
static String strikeBallPrint(int[] result) {
if(result[0] == 0 && result[1] == 0) {
System.out.println("Out입니다.");
}
else if(result[0] == 3) {
System.out.println("홈런입니다.");
return "종료";
}
else {
System.out.println("strike : "+result[0]+
", ball : "+result[1]);
}
return "반복";
}
static void start() {
Random r = new Random();
int[] com = new int[3];
makeRandom(com, r);
while(true) {
String str=
strikeBallPrint(strikeBallCheck(
userInput(), com));
if(str.equals("종료")) {
break;
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
start();
}
}