JAVA 야구게임 판정문 for문
관련링크
본문
int strike = 0 , ball = 0;
int i = 0;
int[] comNum= {1,9,2};
int[] userNum= {1,2,3};
//판정 포문
for (int i = 0; i < comNum.length; i++) { // strike ball 판단하는 조건식
for (int j = 0; j < userNum.length; j++) {
if (comNum[i] == userNum[j]) {
if (i == j) {
strike += 1;
} else
ball += 1;
}
}
}
//판정 포이치문
for(int a : userNum){
int y = 0 ; //초기화를 시켜줘야 다시 검사
for(int b : User){
if(a[i]==b[y]) strike++ ; //순서가 같은것 끼리 같으면
else if(i!=y &&a[i]==b[y]) ball ++;
y++;
}
i++;
}