Skip to content

Instantly share code, notes, and snippets.

@SirMefju
Created March 22, 2021 17:04
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 SirMefju/a7ab56dc81419e5906b13614020bf28e to your computer and use it in GitHub Desktop.
Save SirMefju/a7ab56dc81419e5906b13614020bf28e to your computer and use it in GitHub Desktop.
int round = 1;
int min = 1;
int max = 20;
int number = (int) (Math.random() * (max - min + 1)) + min;
System.out.println("Chose number between 1 - 20");
Scanner in = new Scanner(System.in);
boolean score = false;
while (!score) {
String a = in.nextLine();
int chosen = Integer.parseInt(a);
if (chosen > number) {
System.out.println("Less");
score = false;
round++;
}
if (chosen < number) {
System.out.println("more");
score = false;
round++;
}
if (chosen == number) {
score = true;
}
}
System.out.println("Perfect, You guessed in round: " + round);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment