Created
February 20, 2017 13:40
-
-
Save anonymous/72f99fa4fe5e233716c9d8bad3552dc6 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.Random; | |
import java.util.Scanner; | |
public class HiLo | |
{ | |
public static void main( String[] args ) | |
{ | |
Scanner keyboard = new Scanner(System.in); | |
Random r = new Random(); | |
int tries = 0; | |
int number = 1 + r.nextInt(100); | |
String response = ""; | |
int guess; | |
//FIRST NUMBER GUESS | |
System.out.print("GUESS MY NUMBER"); | |
System.out.print("\nI'm thinking of a number between 1 and 100. You have 7 guesses"); | |
System.out.print("\nENTER YOUR GUESS. \nGuess #" + tries + "\t"); | |
guess = keyboard.nextInt(); | |
tries++; | |
if ( guess > number ) | |
System.out.println("TOO HIGH"); | |
else if ( guess < number ) | |
System.out.println("TOO LOW"); | |
//GUESSING NUMBER LOOP | |
while (guess != number && tries < 7) | |
{ | |
System.out.print("ENTER YOUR GUESS. \nGuess #" + tries + "\t"); | |
guess = keyboard.nextInt(); | |
if ( guess > number ) | |
System.out.println("TOO HIGH"); | |
else if ( guess < number ) | |
System.out.println("TOO LOW"); | |
tries++; | |
} | |
if ( guess == number ) | |
System.out.println("\nRIGHT ON"); | |
else if ( tries == 7 ) | |
System.out.println("\nNO MORE GUESSES"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment