= 실행코드 = {{{~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형으로 받아지기 때문에 문자 하나씩 끊어 읽게끔 해도 되지^^ 조금만 생각해보면 방법이 나올 수도 있어 - [상욱]