Advertisement
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) {
- int random;
- int playerChoice;
- String continueGame;
- Scanner scanner = new Scanner(System.in);
- while(true)
- {
- System.out.println("\f");
- System.out.println("RULES:\nEnter an integer value between 1 and 100.\nYou have 5 tries.");
- int x = 1;
- random = (int)(Math.random() * 100) + 1;
- while(x <= 5)
- {
- System.out.print("Enter your guess: ");
- playerChoice = scanner.nextInt();
- if(playerChoice < 0 || playerChoice > 100)
- {
- System.out.println("Enter a valid number 1 - 100!");
- }
- else if (playerChoice == random)
- {
- System.out.println("Winner, winner, chicken dinner!");
- System.out.println("You tried " + x + " times. You had " + (5 - x) + " tries left.");
- }
- else
- {
- System.out.println("Nope.");
- if(playerChoice > random)
- {
- System.out.println("Your guess was too high :)");
- System.out.println("Guesses left: " + (5 - x ));
- } else if (playerChoice < random)
- {
- System.out.println("Your guess was too low! :(");
- System.out.println("Guesses left: " + (5 - x ));
- }
- x++;
- if(x > 5)
- {
- System.out.println("You have used all your tries. The number was " + random);
- }
- }
- }
- System.out.println("Continue? [Y/N]");
- continueGame = scanner.next().trim();
- if (continueGame.toLowerCase().equals("n"))
- {
- break;
- }
- } // END OF while LOOP
- } // END OF main METHOD
- } // END OF Main CLASS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement