Skip to content

Instantly share code, notes, and snippets.

@mick001
Created August 29, 2015 10:14
Show Gist options
  • Save mick001/4a34ae895a7dee8ab166 to your computer and use it in GitHub Desktop.
Save mick001/4a34ae895a7dee8ab166 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
import java.util.Random;
public class GuessNumberMain
{
public static void main(String[] args)
{
System.out.println("Guess the number beween 0 and 99");
Scanner reader = new Scanner(System.in);
int number = reader.nextInt();
Random randomGenerator = new Random();
int toGuess = randomGenerator.nextInt(100);
while(number != toGuess)
{
if(number < toGuess)
{
System.out.println("Higher");
}else if(number > toGuess)
{
System.out.println("Lower");
}
System.out.println("Try again!");
number = reader.nextInt();
}
System.out.println("Congrats! You guessed it! It was: "+number);
reader.close();
}
}
@TheWitcher2808
Copy link

nice :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment