Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner keyboard = new Scanner(System.in);
- int number = 11;
- int maxAttempts = 7;
- int numberofAttempts = 1;
- int guess;
- int tries = 0;
- int sum = 0;
- System.out.println("I have chosen a number between 1 and 100. You have seven tries. Try to guess it");
- guess = keyboard.nextInt();
- while (guess != number && maxAttempts > numberofAttempts)
- if (guess == number) {
- System.out.println("That is right, you are a good guesser!!");
- } else if (guess < number || numberofAttempts > maxAttempts) {
- System.out.println("Sorry, you are too low.");
- numberofAttempts = numberofAttempts + 1;
- System.out.println("Enter another guess:");
- guess = keyboard.nextInt();
- } else if (guess > number || numberofAttempts > maxAttempts) {
- System.out.println("Sorry, you are too high.");
- numberofAttempts = numberofAttempts + 1;
- System.out.println("Enter another guess:");
- guess = keyboard.nextInt();
- } else if (numberofAttempts >= maxAttempts) {
- System.out.println("You have no more guesses.");
- }
- System.out.println("You have no more tries.");
- }
- }
Add Comment
Please, Sign In to add comment