Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Random;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- boolean isPlaying = true;
- String retry = "";
- Random random = new Random();
- while (isPlaying) {
- System.out.println("***********************************");
- System.out.println("<(<<Welcome To guess the number>>)>");
- System.out.println("***********************************");
- System.out.print("\nPress enter to play...");
- scanner.nextLine();
- int number = random.nextInt(10) + 1;
- System.out.print("Guess a number between 1 and 10: ");
- int guess = scanner.nextInt();
- scanner.nextLine();
- if (guess == number) {
- System.out.print("\nYou won! Do you want to play again?(Yes or No): ");
- }
- else {
- System.out.print("\nYou lost! Do you want to play again?(Yes or No): ");
- }
- retry = scanner.nextLine();
- while (!retry.equalsIgnoreCase("Yes") && !retry.equalsIgnoreCase("No")){
- System.out.print("\nInvalid! please type YES or NO: ");
- retry = scanner.nextLine();
- }
- isPlaying = retry.equalsIgnoreCase("Yes");
- }
- scanner.close();
- System.out.println("Thanks for playing!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement