본문 바로가기

JAVA/Example

주사위 두개를 던졌을 때 나오는 눈을 (x,y) 형태로 출력하고, 눈의 합의 5가 될때까지 무간지옥에서 벗어날수 없습니다(단, 면이 6개인 평범한 주사위임)


public class main {

	public static void main(String[] args) {
		//두개 주사위 던져서 나오는눈을 (눈1,눈2)형태 출력 , 눈의합이 5면 실행멈추기
		System.out.println("주사위 두개의 합이 5 이면 멈춥니다");
		int x = (int) (Math.random()*6)+1;
		int y = (int) (Math.random()*6)+1;
		while((x+y)!=5){
			System.out.println("("+x+","+y+")");
			x = (int) (Math.random()*6)+1;
			y = (int) (Math.random()*6)+1;
		}
		System.out.println("("+x+","+y+")");

	}

}