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 is

import java. util. scanner;
import java. util. random;
public class guessinggame
{
public static void main(string [] args)
{
//create a scanner object to read from the keyboard
scanner kb = new scanner(system. in);
//create a random object
random rand = new random();
//identifier declarations
int 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: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 23:00
Is an attack that relies on guessing the isns of tcp packets
Answers: 2
question
Computers and Technology, 23.06.2019 19:30
2. fluorine and chlorine molecules are blamed fora trapping the sun's energyob forming acid rainoc producing smogod destroying ozone molecules
Answers: 2
question
Computers and Technology, 23.06.2019 21:30
Enzo’s balance sheet for the month of july is shown. enzo’s balance sheet (july 2013) assets liabilities cash $600 credit card $4,000 investments $500 student loan $2,500 house $120,000 mortgage $80,000 car $6,000 car loan $2,000 total $127,100 total $88,500 which expression finds enzo’s net worth?
Answers: 1
question
Computers and Technology, 24.06.2019 07:40
What type of multimedia are live news feeds? live news feeds are examples of multimedia.
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, 11.09.2019 18:10
question
Mathematics, 11.09.2019 18:10
Questions on the website: 13722362