Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class GuessingGame {
- public static void main(String[] args) {
- //Scanner
- Scanner sc = new Scanner (System.in);
- //Declaring Variables outside of loop.
- int endGame;
- int max = 10;
- int min = 1;
- int randomNum = (int) (Math.random() * (max - min + 1)) + min;
- //Directions
- System.out.println("In this game, you only have three guesses, so use them wisely!");
- //This print makes the game look aesthetically pleasing.
- System.out.println("--------------------------------------------------------------\n");
- //Loop that runs the game until they choose to be done playing.
- do {
- //For Loop limits user to 3 guesses.
- for (int i = 1; i <=3; i++) {
- System.out.print("Guess the number between 1 and 10: ");
- int guess = sc.nextInt();
- if (guess == randomNum) {
- i = 4;
- System.out.println("Winner!");
- }
- else if (guess != randomNum) {
- System.out.print("Guess " + i + " was Wrong.\n\n");
- }
- }
- System.out.print("If you would like to play again enter 1. If You would like to quit, enter 2:");
- endGame = sc.nextInt();
- //These if/else statements, once again for the aesthetics of the program.
- if (endGame == 1) {
- System.out.println("\nNew Round\n---------\n");
- }
- else if (endGame == 2) {
- //I just like the way the underlines look.
- System.out.println("\n------------");
- System.out.println(" Game Ended");
- System.out.println("------------");
- }
- }while(endGame==1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement