import java.util.Random;
import java.util.Scanner;

public class Smugogae {
	public static void main(String[] args) {
		Random ran = new Random();
		Scanner in = new Scanner(System.in);
		int val = ran.nextInt(20) + 1;
		int input;
		int cnt = 0;

		System.out.println("답:" + val);

		System.out.println("스무고개(1~20)");
		do {
			System.out.print("input : ");
			input = in.nextInt();
			if (val > input) {
				System.out.printf("%d보다 큽니다.\n", input);
			} else if (val < input) {
				System.out.printf("%d보다 작습니다.\n", input);
			}
			cnt++;
			System.out.println("count " + cnt);
		} while (input != val && cnt < 20);

		if (cnt > 20) {
			System.out.println("val = " + val);
			System.out.println("20번이 넘었습니다.");
		} else {
			System.out.println("val = " + val);
			System.out.println("count = " + cnt);
		}
	}
}

+ Recent posts