Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

BasicJAVA2005/실습1/송수생

From ZeroWiki
Revision as of 05:22, 7 February 2021 by imported>Unknown
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

숫자 야구 게임

짜다 보니깐 현태꺼와 매우 흡사..ㅜㅜ

import java.util.*;
public class game {

	public static void main(String[] args) {
		Random number = new Random(); 
		int[] arry = new int[3];
		int[] temp = new int[3];
		int strike=0;
		int ball=0;
		
		for(int i=0; i<3; i++)
		{
			arry[i]=number.nextInt(9);

		}
		System.out.println("입력:");
		while(strike!=3)
		{	
			strike=0;
			ball=0;
			
			Scanner scannumber = new Scanner(System.in);
			for(int i =0; i<3; i++)
			{
				temp[i]=scannumber.nextInt();
			}
			for(int i=0; i<3; i++)
			{
				if(arry[i]==temp[i])
					strike++;
				else for(int j=0; j<3; j++)
				{
					if(arry[i]==temp[j])
						ball++;
				}			
			}
		System.out.print("Strike=");
		System.out.print(strike);
		System.out.print("Ball=");
		System.out.println(ball);
		}
	}		
}

BasicJAVA2005, BasicJAVA2005/실습1