Created
September 30, 2015 22:25
-
-
Save ornirus/bb3d4ecbff1562b0f7d5 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.*; | |
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