import [Link].
Random;
import [Link];
public class NumberGuessingGame {
public static void main(String[] args) {
Random random = new Random();
Scanner scanner = new Scanner([Link]);
int secretNumber = [Link](100) + 1; // Generates a random number
between 1 and 100
int guess;
int attempts = 0;
[Link]("Welcome to the Number Guessing Game!");
[Link]("I'm thinking of a number between 1 and 100.");
do {
[Link]("Enter your guess: ");
guess = [Link]();
attempts++;
if (guess < secretNumber) {
[Link]("Too low!");
} else if (guess > secretNumber) {
[Link]("Too high!");
} else {
[Link]("Congratulations! You guessed the number in " +
attempts + " attempts.");
break;
}
} while (true); // Continues until the player guesses correctly
[Link](); // Close the scanner to prevent resource leaks
}
}