Last active
August 29, 2015 14:27
-
-
Save tenifni/2ea0b5239460e25831da to your computer and use it in GitHub Desktop.
[Game] Java Guessing Game. Randomly creates an integer between 1~1000. User tries to guess the number.
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 Practive{ | |
public static void main (String[] args){ | |
Random rand = new Random(); | |
int numberToGuess = rand.nextInt(1000); | |
int numberOfTries = 0; | |
Scanner input = new Scanner (System.in); | |
int guess; | |
boolean win = false; | |
while (win == false){ | |
System.out.println ("enter an interger btw 1- 1000"); | |
guess = input.nextInt(); | |
numberOfTries++; | |
if (guess == numberToGuess){ | |
win = true; | |
} | |
else if (guess < numberToGuess){ | |
System.out.println("your guess is too low"); | |
} | |
else if (guess >numberToGuess){ | |
System.out.println("your guess is too high"); | |
} | |
} | |
if (numberOfTries <= 6){ | |
System.out.println ("You got it! The numeber was "+ numberToGuess + ". It took you "+ numberOfTries +" tries. IMPRESSIVE!!"); | |
} | |
if (numberOfTries >6){ | |
System.out.println ("Well, you finally got it! The numeber was "+ numberToGuess + ". It took you "+ numberOfTries +" tries. Good Job!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment