Created
July 24, 2016 16:12
-
-
Save jimgao1/41f8c07d7476cb4c82c57d5f62d667cf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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