Skip to content

Instantly share code, notes, and snippets.

@ornirus
Created September 30, 2015 22:25
Show Gist options
  • Save ornirus/bb3d4ecbff1562b0f7d5 to your computer and use it in GitHub Desktop.
Save ornirus/bb3d4ecbff1562b0f7d5 to your computer and use it in GitHub Desktop.
import java.util.*;
public class NumberGuesser
{
Random rn = new Random();
Scanner reader = new Scanner(System.in);
private int x, y;
private boolean guess = false;
public void newNumber(int z) {
x = rn.nextInt(z) + 1;
guess = false;
guess();
}
public void guess() {
while (guess == false) {
System.out.println("Enter Guess");
y = reader.nextInt();
if (y < 0){
guess = true;
}
if (y != x) {
System.out.println("Guess again");
}
else {
System.out.println("Correct!");
guess = true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment