import java.util.Scanner; /* * 1~100사이의 값 * 숫자맞추기게임 */ public class Ex5 { public static void main(String[] args) { // TODO Auto-generated method stub int answer = (int) (Math.random()*100); int input = 0; int count =0; Scanner s = new Scanner(System.in); while(true) { count++; System.out.println("1과 100사이의 값을 입력하세요 : "); input = s.nextInt(); if(input==answer){ System.out.println("정답입니다."); System.out.printf("시도횟수는 %d번입니다.\n", count); }else if(input > answer){ System.out.println("더 작은 수를 입력하세요."); }else if(input < answer){ System.out.println("더 큰 수를 입력하세요."); } } } }
반응형
'프로그래밍' 카테고리의 다른 글
FND(device driver) (0) | 2015.04.15 |
---|---|
mysh.c (0) | 2015.04.13 |
삼각형,사각형 출력 (0) | 2015.04.07 |
아두이노 기초 스터디 계획안 (0) | 2015.04.01 |
System call을 통한 LED 제어 (0) | 2015.04.01 |