숫자 맞추기 겜

개발/코딩 2013. 10. 11. 20:25

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

public class 연습 {
 public static void main(String[] args) {
  Scanner scan = new Scanner(System.in);
  Random rand = new Random();
  int j = rand.nextInt(100);
  int k = 1;
  int low=0;
  int high=100;
  while (k == 1) {
   int i = scan.nextInt();
   if (j < i) {
    System.out.println("더 낮게");
    high=i;
    System.out.printf(low+"-"+high);
    
   } else if (j > i) {
    System.out.println("더 높게");
    low=i;
    System.out.printf(low+"-"+high);
   }
   else if (j == i) {
    System.out.println("맞다");
    System.out.println("다시 하겠습니까?(1/2)");
    k = scan.nextInt();
    if(k==1){
    System.out.println("시작");
    j = rand.nextInt(100);
    high=100;
    low=0;
    }
    else{
     System.out.println("종료");
     }
    }
   }
  }
 }

 

'개발 > 코딩' 카테고리의 다른 글

JSP특징  (0) 2013.11.15
비행기 겜 완성  (0) 2013.10.21
비행기  (0) 2013.10.11
삽입 정렬  (0) 2013.10.11
그림 파일불러오기  (0) 2013.10.10