U E D R , A S I H C RSS

JTD Study/첫번째과제/��

실행코드

~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형으로 받아지기 때문ì—� 문ìž� 하나씩 ë�Šì–´ ì�½ê²Œë�” í•´ë�„ ë�˜ì§€^^ 조금만 ìƒ�ê°�í•´ë³´ë©´ 방법ì�´ 나올 수ë�„ 있어 - ìƒ�ìš±
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:29
Processing time 0.0045 sec