andreaholeon

Untitled

Dec 9th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner keyboard = new Scanner(System.in);
  8.  
  9.         int number = 11;
  10.         int maxAttempts = 7;
  11.         int numberofAttempts = 1;
  12.         int guess;
  13.         int tries = 0;
  14.         int sum = 0;
  15.  
  16.  
  17.         System.out.println("I  have chosen a number between 1 and 100. You have seven tries. Try to guess it");
  18.         guess = keyboard.nextInt();
  19.  
  20.         while (guess != number && maxAttempts > numberofAttempts)
  21.             if (guess == number) {
  22.                 System.out.println("That is right, you are a good guesser!!");
  23.             } else if (guess < number || numberofAttempts > maxAttempts) {
  24.                 System.out.println("Sorry, you are too low.");
  25.                 numberofAttempts = numberofAttempts + 1;
  26.                 System.out.println("Enter another guess:");
  27.                 guess = keyboard.nextInt();
  28.             } else if (guess > number || numberofAttempts > maxAttempts) {
  29.                 System.out.println("Sorry, you are too high.");
  30.                 numberofAttempts = numberofAttempts + 1;
  31.                 System.out.println("Enter another guess:");
  32.                 guess = keyboard.nextInt();
  33.             } else if (numberofAttempts >= maxAttempts) {
  34.                 System.out.println("You have no more guesses.");
  35.  
  36.                 }
  37.  
  38.         System.out.println("You have no more tries.");
  39.  
  40.  
  41.             }
  42.     }
Add Comment
Please, Sign In to add comment