Computers and Technology

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); }}

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 13:30, baeethtsadia
Asoftware company hired ray, a college graduate to work in their development team. ray is assigned to work in the coding phase of a project. what happens during the coding phase of a software development project? a. the customer receives a working model of the software. b. developers convert the program design into code. c. developers gather requirements directly from the stakeholders. d. testing teams check the product for quality.
Answers: 1
image
Computers and Technology, 22.06.2019 17:00, DRock4976
Which of the following is not contained on the slide show toolbar? a. next button b. slide button c. close button d. pen too
Answers: 2
image
Computers and Technology, 23.06.2019 11:20, 1tzM3
Http is the protocol that governs communications between web servers and web clients (i. e. browsers). part of the protocol includes a status code returned by the server to tell the browser the status of its most recent page request. some of the codes and their meanings are listed below: 200, ok (fulfilled)403, forbidden404, not found500, server errorgiven an int variable status, write a switch statement that prints out the appropriate label from the above list based on status.
Answers: 2
image
Computers and Technology, 23.06.2019 16:00, cravens511peeelg
An english teacher would like to divide 8 boys and 10 girls into groups, each with the same combination of boys and girls and nobody left out. what is the greatest number of groups that can be formed?
Answers: 2
Do you know the correct answer?
Write a program that generates a random number and asks the user to guess what the number is. if the...

Questions in other subjects:

Konu
Mathematics, 18.07.2019 08:50
Konu
Mathematics, 18.07.2019 08:50