-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathh1.java
More file actions
executable file
·32 lines (31 loc) · 970 Bytes
/
h1.java
File metadata and controls
executable file
·32 lines (31 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.Scanner;
/**
* Created by Alec on 9/1/16.
*/
public class h1 {
public static void main(String[] args){
int guess = 50;
int upperbound = 100;
int lowerbound = 1;
boolean found = false;
Scanner input = new Scanner(System.in);
while (found != true){
System.out.println("Is your number " + guess + "?(Y/N)");
if (input.next().equalsIgnoreCase("Y")){
found = true;
}
else {
System.out.println("Higher or lower?");
if(input.next().equalsIgnoreCase("Higher")){
lowerbound = guess;
guess += (upperbound - lowerbound)/2;
}
else {
upperbound = guess;
guess -= (upperbound - lowerbound)/2;
}
}
}
System.out.println("Your number is " + guess + "!");
}
}