Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- public class game
- {
- public static void main(String Args [])
- {
- System.out.println("Let's play Guess that Game!");
- Random rand = new Random();
- Scanner getInput = new Scanner(System.in);
- Boolean areWeDone = false;
- int high = 100;
- int low = 1;
- int guess = 0;
- int computerNumber = 0;
- int tries = 0;
- computerNumber = rand.nextInt(100)+1;
- while (areWeDone == false)
- {
- ++tries;
- System.out.println("Guess a number between " +low+" and "+high+".");
- guess = getInput.nextInt();
- if (guess < high && guess > low)
- {
- if (guess == computerNumber)
- {
- System.out.println("You did it! You have guessed the correct answer.");
- System.out.println("You took "+tries+ " tries.");
- areWeDone = true;
- }
- else if (guess > computerNumber)
- {
- System.out.println("You have answered incorrectly. Please try again.");
- high = guess;
- }
- else if (guess < computerNumber)
- {
- System.out.println("You have answered incorrectly. Please try again.");
- low = guess;
- }
- }
- else
- {
- System.out.println("You have an out of range guess. Stop being stupid and read the question.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement