27.0k views
1 vote
Write a program that selects a random number between 1 and 5 and asks the user to guess the number. Display a message that indicates the difference between the random number and the user’s guess. Display another message that displays the random number and the Boolean value true or false depending on whether the user’s guess equals the random number.

1 Answer

6 votes

Answer:

Following is given the program code as required:

Step-by-step explanation:

  • Initially a class is created name RandomGuessMatch.java
  • An instance for scanner class is created in main method.
  • Now the upper and lower bounds for guess are given by variables MIN (1) and MAX(5).
  • Now user will be allowed to guess the number.
  • The difference between the guessed number and actual number is calculated.
  • This will tell the compiler weather to print correct or incorrect.

i hope it will help you!

Write a program that selects a random number between 1 and 5 and asks the user to-example-1
Write a program that selects a random number between 1 and 5 and asks the user to-example-2
User Cethegeek
by
5.7k points