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 23:30
4.11 painting a wall (1) prompt the user to input integers for a wall's height and width. calculate and output the wall's area (integer). note that in this case there is a new line after each prompt. (submit for 1 point). enter wall height (feet): 11 enter wall width (feet): 15 wall area: 165 square feet (2) extend to also calculate and output the amount of paint in gallons needed to paint the wall (floating point). assume a gallon of paint covers 350 square feet. store this value in a variable. output the amount of paint needed using the %f conversion specifier. (submit for 2 points, so 3 points total). enter wall height (feet): 11 enter wall width (feet): 15 wall area: 165 square feet paint needed: 0.471429 gallons (3) extend to also calculate and output the number of 1 gallon cans needed to paint the wall. hint: use a math function to round up to the nearest gallon. (submit for 2 points, so 5 points total). enter wall height (feet): 11 enter wall width (feet): 15 wall area: 165 square feet paint needed: 0.471429 gallons
Answers: 3
question
Computers and Technology, 23.06.2019 04:00
In a word processing program, such as microsoft word, which feature to you choose the desired picture enhancement?
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
Name the range function that would generate the following list of integers values: 0,1,2,3,4,5.
Answers: 1
question
Computers and Technology, 24.06.2019 07:00
Selective is defined as paying attention to messages that are consistent with one’s attitudes and beliefs and ignoring messages that are inconsistent.
Answers: 1
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, 15.08.2020 20:01
Questions on the website: 13722362