Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I'm supposed to create a code that imitates a guessing game where the computer generates a random number, asks for user input, and informs them
I'm supposed to create a code that imitates a guessing game where the computer generates a random number, asks for user input, and informs them if they are over the number or under.
for some reason, the computer does not properly recieve the input of code and makes me input the number multiple times to recognize the input.
is it a computer error or is something
wrong with my code?
mport java.util. Random; import java.util.Scanner; * Part A: A simple guessing game. Keep guessing numbers until you get the correct answer. The goal of the game * is to complete it using as little guesses as possible. */ no usages public class Main {I no usages public static void main(string[] args) \{ II main method start var RandomNumber = new Random( ); I/ random object(number) final int UPPER_BOUND =10;// Upper Bound variable final int myRandomVaLue = RandomNumber.nextInt(UPPER_BOUND); var scanobject = new Scanner (System. in); int counter =0; System.out.println("Please enter your guess."); int quess = scanobject. nextint ();// make guess here while (guess t= myRandomvalue) \{ if (myRandomvalue = scanobject. nextint ();// make guess here counter = counter +1; if (myRandomvalue > guess) System.out.println("Incorrect. Value is too small. Please enter another guess."); quess = scanobject. nextInt();// make guess here counter = counter +1; if (myRandombalue = guess) f counter = counter +1; system, out. printin("Correct! Took " + counter + "guesses"); break; 3 ; 33Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started