No older revisions available
No older revisions available
실행코드 ¶
~cpp code
import javax.swing.JOptionPane;
public class baseballGame {
public static void main(String [] args){
int[] num = new int[3];
int i, j ;
num[0] = (int)(Math.random()*10);
num[1] = (int)(Math.random()*10);
num[2] = (int)(Math.random()*10);
for(;;){
int strikeCounter = 0, ballCounter = 0;
int[] temp = new int[3];
int answer = Integer.parseInt(JOptionPane.showInputDialog("세자리수를 입력하세요"));
temp[0] = answer/100;
temp[1] = answer/10%10;
temp[2] = answer%10;
for(i = 0; i <3; i++){
for(j = 0; j <3; j++){
if (num[i] == temp[j] && i == j)
strikeCounter++;
else if(num[i] == temp[j] && j != i && num[j] != temp[j])
ballCounter++;
}
}
JOptionPane.showMessageDialog(null, strikeCounter +"strike" + ballCounter + "ball");
if(strikeCounter == 3){
JOptionPane.showMessageDialog(null, "your answer is right!");
break;}
}
}
}
잡담 ¶
- Good~! 같이 진행사람이 있었다니...^^; - 상욱
- 짜긴 짯는데, 하고 보니 어째 쫌 조잡하네요 영준