Skip to content

Instantly share code, notes, and snippets.

@jimgao1
Created July 24, 2016 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimgao1/41f8c07d7476cb4c82c57d5f62d667cf to your computer and use it in GitHub Desktop.
Save jimgao1/41f8c07d7476cb4c82c57d5f62d667cf to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int low = 1, high = 100;
while(low != high){
int mid = (low + high) / 2;
System.out.printf("low = %d, high = %d, mid = %d\n", low, high, mid);
String in = sc.next();
if (in.equals("low")){
low = mid + 1;
} else if (in.equals("high")){
high = mid - 1;
} else if (in.equals("end")){
break;
}
}
System.out.println("The number is " + low);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment