006-003-010

Implementing a Number Guessing Game with while

Hard

Problem Description

Implementing a Number Guessing Game with while

In this problem, you will create a program that repeatedly reads integer input until the user guesses the target value (7), prints a comparison result on each attempt, and displays the total number of attempts upon a correct guess to standard output.

Learning Objective: Understand combining while loops with condition checking in a practical program

Overview

Create a number guessing program that repeats input until the target number is matched.

Specifications

  1. Target value is 7
  2. Repeatedly read integers with Scanner
  3. If input is above target, print Too high
  4. If input is below target, print Too low
  5. On match, print Correct! Attempts: <n> and exit the loop

Input Example

5
9
7

Output Format

Too low
Too high
Correct! Attempts: 3

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up