Question: Task : Write and run Java code for the following (similar to last slide in the Lecture 11 slides) 1.Program sets a variable X to

Task: Write and run Java code for the following (similar to last slide in the Lecture 11 slides)

  • 1.Program sets a variable X to an integer value (e.g. 7).
  • 2.Program prompts the user to guess the value of X (1
  • 3.After reading the users guess:
    • If the guess equals X, program prints Success (does not repeat anymore)
    • If the guess is less than X, it prints Smaller than X, and repeats = goes back to step 2.
    • If the guess is larger than X, it prints Larger than X, and repeats = goes back to step 2.
    • Note: going back to step 2 = need a loop
    • Your program does not need to worry if the number is outside [1..20] you may assume the user will enter the value in the correct range
  • Finally prints "Goodbye from " followed by your own name. Need your name to get the points.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!