Thanks to visit codestin.com
Credit goes to www.scribd.com

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

Guessing Number

The document contains code for a guessing game that generates a random number between 0 and 100, prompts the user to guess the number, and provides feedback if the guess is too high, too low, or correct until the user guesses correctly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views1 page

Guessing Number

The document contains code for a guessing game that generates a random number between 0 and 100, prompts the user to guess the number, and provides feedback if the guess is too high, too low, or correct until the user guesses correctly.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

Scanner;

public class GuessingNumber {

public static void main(String[] args) {


int secretNumber;

secretNumber = (int) (Math.random() * 100);


Scanner keyboard = new Scanner(System.in);
int guess;
do {
System.out.print("Enter a guess (0-100): ");
guess = keyboard.nextInt();
if (guess == secretNumber)
System.out.println("Your guess is correct. ");
else if (guess < secretNumber)
System.out.println("Your guess is too small. ");
else if (guess > secretNumber)
System.out.println("Your guess is too high. ");

} while (guess != secretNumber);


}
}

You might also like