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, 22.06.2019 05:30
Gerard is currently working as an entry-level customer support technician, but he would like to someday become a software developer. what is the best first step to understand what he should do? ask his manager for a new job or at least a job recommendation study graphic design in order to obtain the necessary skills use career resources to investigate what skills and education are required work part-time as an entry-level web developer question 13 (true/false worth 6 points) (08.03 lc) career resources are used to explore career options and find career information. true false question 14(multiple choice worth 6 points) (08.01 mc) classify the following skills: writing html code, evaluating color theory, using design principles. hard skills interpersonal skills people skills soft skills question 15 (true/false worth 6 points) (08.03 lc) a mentor is a person who is advised, trained, or counseled by a trusted mentee. true false
Answers: 2
question
Computers and Technology, 22.06.2019 16:00
If a client wants to make minor edits, what should he/she use?
Answers: 3
question
Computers and Technology, 23.06.2019 03:50
Iam a bacterium. i cause stomach cramps and diarrhea. i am caused by eating rotten foodssuch as chicken, fish, or eggs. sometimes turtles carry my bacteria.what am i?
Answers: 2
question
Computers and Technology, 23.06.2019 22:00
Technician a says engine assemblies can be mounted longitudinally in a chassis. technician b says engine assemblies can be mounted transversely in a chassis. who is correct?
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, 30.08.2021 02:30
question
Biology, 30.08.2021 02:40
Questions on the website: 13722360