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("I chose a number between 1-100. You have 7 tries to guess the number.");
- int guess = 0;
- while (x != guess && tries <= 7) {
- System.out.println("Guess #"+(tries++)+": ");
- guess = keyboard.nextInt();
- if (x == guess){
- System.out.println("You guessed it! What are the chances?");
- break;
- }
- else if (x > guess && tries <= 7){
- System.out.println("Your guess is too low.");
- }
- else if (x < guess && tries <= 7){
- System.out.println("Your guess is too high.");
- } if (tries >= 7 && x != guess){
- System.out.println("You didn't guess the number in 7 tries. L");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement