~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 받 문 문 끊 끔 ^^ 만 보면 방 -