0% found this document useful (0 votes)
8 views1 page

Import Java

The document contains a Java program for a guessing game where the user must guess a randomly generated number between 1 and 100. The program provides feedback on whether the guess is too high or too low and tracks the number of attempts. The user's score is calculated based on the number of guesses made.

Uploaded by

absalfatima11
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Import Java

The document contains a Java program for a guessing game where the user must guess a randomly generated number between 1 and 100. The program provides feedback on whether the guess is too high or too low and tracks the number of attempts. The user's score is calculated based on the number of guesses made.

Uploaded by

absalfatima11
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import [Link].

Scanner;

public class GuessGame {


public static void main(String[] args) {

int randomNumber = (int)([Link]() * 100) + 1;

Scanner input = new Scanner([Link]);


int guess;
int guesses = 0;

while (true) {
[Link]("Guess the number between 1 and 100: ");
guess = [Link]();
guesses++;

if (guess == randomNumber) {
[Link]("🎉 Correct! You guessed the number!");
break;
}
else if (guess > randomNumber) {
[Link]("Your guess is TOO HIGH! Try again.");
}
else if (guess < randomNumber) {
[Link]("Your guess is TOO LOW! Try again.");
}
}
int score = 100 - guesses;
[Link]("You guessed it in " + guesses + " tries.");
[Link]("Your score: " + score);
}
}

You might also like