~cpp code
import javax.swing.*;
//import java.io.*;
public class NumberBaseballGame {
public static void main(String[] args){
int[] comNum = new int[3];
comNum[0] = (int)(Math.random() * 10 +1);
comNum[1] = (int)(Math.random() * 10 +1);
comNum[2] = (int)(Math.random() * 10 +1);
int[] userNum = new int[3];
int strikeCounter = 0, ballCounter=0, outCounter=0;
int i, j;
for(i=0;i<3;i++){
if (comNum[i] == 10){
comNum[i] --;
}
}
for(;;){
userNum[0] = Integer.parseInt(JOptionPane.showInputDialog(null," 를 력"));
userNum[1] = Integer.parseInt(JOptionPane.showInputDialog(null,"두 를 력"));
userNum[2] = Integer.parseInt(JOptionPane.showInputDialog(null," 를 력"));
//String temp = JOptionPane.showInputDialog(null,"를 력 ( )");
strikeCounter = 0;
ballCounter = 0;
for(i = 0; i < 3; i++){
for(j = 0; j < 3; j++){
if (comNum[i] == userNum[j] && i == j)
strikeCounter++;
else if(comNum[i] == userNum[j] && j != i && (comNum[j] != userNum[j]))
ballCounter++;
}
}
if(strikeCounter == 3){
JOptionPane.showMessageDialog(null, "3strike!! You win!");
break;
}
outCounter++;
JOptionPane.showMessageDialog(null, strikeCounter +"strike " + ballCounter + "ball " + outCounter + "out!");
if(outCounter == 3 && strikeCounter == 0){
JOptionPane.showMessageDialog(null,"?ㅋ Game Over");
break;
}
}
}
}
== ==
다가
보
까
막
똑같
;;;ㅠㅠ
바가
기
라
,
개
력
때 1 2 3
렇게
력
면 배
1,2,3
렇게 들
가게
려고 노력
봤
만
렵
......ㅠㅠ
각
로 결국
따로따로
력
기......
- 방법 러 방법 . 만 100리라면, int 값만 가고 나머는 리는 123%10 면 3 나고, 12%10 면 2 나고 나머는 1고... 런로 른 나 고, 력 String로 기 때문 문 나 끊 게끔 되^^ 만 각보면 방법 나 -