1. CLASS


import java.util.*;


public class HIGH_001 {

  public static void main(String[] args) {

    Scanner keyboard =  new Scanner(System.in);
    int H = 100;
    int L = 0;
    int fguess=(H+L)/2;
    int A;


    int loopCount = 1;
    String que = "c";

    System.out.println ("Think of a number between "+100+" and "+L+"." );
    A = keyboard.nextInt();
  
    while(true){
      // System.out.println("Is the number "+ fguess + "\n");
   
      if(fguess > A){

        que = "l";
        H = H/2; 

      }else if(fguess < A){

        que = "h";
        L = H/2;
      }else if(fguess == A){
        System.out.println("Number of guesses: " + loopCount);
        break;
      }else{
        System.out.println("Only 1 ~ 100 NUMBER");
      }
      fguess += H - L;

      System.out.println("Is the number "+ fguess + " (Correct, Low, High) ? " + que + "\n");

      loopCount++;
    }
  }

}



2. RUN


Think of a number between 100 and 0.
78
Is the number 100 (Correct, Low, High) ? h

Is the number 100 (Correct, Low, High) ? l

Is the number 75 (Correct, Low, High) ? l

Is the number 88 (Correct, Low, High) ? h

Is the number 88 (Correct, Low, High) ? l

Is the number 82 (Correct, Low, High) ? l

Is the number 73 (Correct, Low, High) ? l

Is the number 75 (Correct, Low, High) ? h

Is the number 77 (Correct, Low, High) ? h

Is the number 79 (Correct, Low, High) ? h

Is the number 79 (Correct, Low, High) ? l

Is the number 78 (Correct, Low, High) ? l

Number of guesses: 13