More actions
imported>Unknown No edit summary |
(Repair batch-0002 pages from live compare) |
||
| Line 4: | Line 4: | ||
public class baseballGame { | public class baseballGame { | ||
public static void main(String | public static void main(String [] args){ | ||
int | int[] num = new int[3]; | ||
int i, j ; | int i, j ; | ||
num | num[0] = (int)(Math.random()*10); | ||
num | num[1] = (int)(Math.random()*10); | ||
num | num[2] = (int)(Math.random()*10); | ||
for(;;){ | for(;;){ | ||
int strikeCounter = 0, ballCounter = 0; | int strikeCounter = 0, ballCounter = 0; | ||
int | int[] temp = new int[3]; | ||
int answer = Integer.parseInt(JOptionPane.showInputDialog("세자리수를 입력하세요")); | int answer = Integer.parseInt(JOptionPane.showInputDialog("세자리수를 입력하세요")); | ||
temp | temp[0] = answer/100; | ||
temp | temp[1] = answer/10%10; | ||
temp | temp[2] = answer%10; | ||
for(i = 0; i <3; i++){ | for(i = 0; i <3; i++){ | ||
for(j = 0; j <3; j++){ | for(j = 0; j <3; j++){ | ||
if (num | if (num[i] == temp[j] && i == j) | ||
strikeCounter++; | strikeCounter++; | ||
else if(num | else if(num[i] == temp[j] && j != i && num[j] != temp[j]) | ||
ballCounter++; | ballCounter++; | ||
} | } | ||
| Line 41: | Line 41: | ||
= 잡담 = | = 잡담 = | ||
* Good~! 같이 진행사람이 있었다니...^^; - [[상욱]] | * Good~! 같이 진행사람이 있었다니...^^; - [[상욱]] | ||
* 짜긴 짯는데, 하고 보니 어째 쫌 조잡하네요 ;; | * 짜긴 짯는데, 하고 보니 어째 쫌 조잡하네요 ;; 영준 | ||
Latest revision as of 00:16, 27 March 2026
실행코드
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~! 같이 진행사람이 있었다니...^^; - 상욱
- 짜긴 짯는데, 하고 보니 어째 쫌 조잡하네요 ;; 영준