subject

Write a program that generates a random number and asks the user to guess what the number is. if the user's guess is higher than the random number, the program should display "too high, try again." if the user's guess is lower than the random number, the program should display "too low, try again." the program should use a loop that repeats until the user correctly guesses the random number. you shall also keep a count of the number of guesses that the user makes. when the user correctly guesses the random number, the program should display the number of guesses. now add another loop to ask the user if he or she wishes to play the guessing game again. if so, the loop should repeat, otherwise it should terminate. so far, this is what my program looks like, any or suggestions would be greatly appreciated! // this program generates a random number and askes the user to guess what the number isimport java. util. scanner; import java. util. random; public class guessinggame{public static void main(string [] args){//create a scanner object to read from the keyboardscanner kb = new scanner(system. in); //create a random objectrandom rand = new random(); //identifier declarationsint num = rand. nextint(100) + 1; int guess = 0; int count = 0; int guesses = 0; do{system. out. println("guess what number i have (1-100)? "); guess = kb. nextint(); guesses ++; if(num > guess) {system. out. println("too high, try again."); } else if(num < guess) {system. out. println("too low, try again."); } else {system. out. println("you're right, the number is" + num); system. out. println("you guessed" + guesses + "times"); }}while(guess! =num); }}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 20:50
What are the advantages of google cloud ?
Answers: 2
question
Computers and Technology, 21.06.2019 22:00
Which one of the following identifies the primary a purpose of information classification processes? a. define the requirements for protecting sensitive data.b. define the requirements for backing up data.c. define the requirements for storing data.d. define the requirements for transmitting data.
Answers: 2
question
Computers and Technology, 22.06.2019 22:00
Discuss the ways in which electronic information associated with payments is addressed in terms of security. include encryption, secure sockets layers, and secure electronic transactions in your discussion. are there any other ways that consumers and businesses can keep their payment information secure in an electronic commerce environment? do you feel that your information is safe when conducting electronic business? why or why not?
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
Jason needs to learn a new web tool. he went through his books to understand more about it. now he wants hands-on experience with using that tool. what would him? jason can use websites where workspace is provided to test the results of your code.
Answers: 2
You know the right answer?
Write a program that generates a random number and asks the user to guess what the number is. if the...
Questions
question
Mathematics, 19.05.2021 15:50
question
Mathematics, 19.05.2021 15:50
question
Geography, 19.05.2021 15:50
question
Social Studies, 19.05.2021 15:50
question
Arts, 19.05.2021 15:50