// LAB 숫자 추측 게임
public class Test01 {
public static void main(String[] args) {
int answer = (int)(Math.random()*100)+1;
int guess;
int cnt = 0;
Scanner sc = new Scanner(System.in);
do {
System.out.print("정답을 추측하여 보시오: ");
guess = sc.nextInt();
cnt++;
if (guess > answer)
System.out.println("제시한 정수가 높습니다.");
if (guess < answer)
System.out.println("제시한 정수가 낮습니다.");
} while (guess != answer);
System.out.println("축하합니다. 시도횟수="+ cnt);
}
}
댓글 없음:
댓글 쓰기