Created
October 18, 2021 18:29
-
-
Save archigoodvin07/eb84d71e5962e9671663066d96e651d4 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; | |
class GuessTheNumber { | |
public static void main(String[] args) { | |
Scanner s = new Scanner(System.in); | |
int min = 1; | |
int max = 100; | |
while (true) { | |
int guess = (min + max) / 2; | |
System.out.println("Hi. Can I try to guess. Your number " + guess + "?"); | |
String line = s.nextLine(); | |
if (line.equals(">")) { // Press ">" if your number is bigger | |
min = guess; | |
} | |
else if (line.equals("<")) { // Press "<" if your number is lower | |
max = guess; | |
} else if (line.equals("=")) { // Press "=" if your number is equal | |
System.out.println("Congrats!"); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment