Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Random r = new Random();
- int x = 1 + r.nextInt(100);
- Scanner keyboard = new Scanner(System.in);
- int tries = 1;
- System.out.println("GUESS THE NUMBER IM THINKING");
- System.out.println("Im thinking of a number between 1-100. You have 7 tries");
- int guess = 0;
- while (x != guess && tries <= 7) {
- System.out.print("Guess #" + (tries++) + ": ");
- guess = keyboard.nextInt();
- if (x == guess) {
- System.out.println("You win! What are the odds?!?");
- break;
- } else if (x > guess && tries <= 7) {
- System.out.println("Sorry, you are too low.");
- } else if (x < guess && tries <= 7) {
- System.out.println("Sorry, you are too high.");
- }
- }
- if (tries >= 7 && x != guess) {
- System.out.println("Sorry, you didn\'t guess it in 7 guesses. You lose.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement