Skip to content

Instantly share code, notes, and snippets.

@YousufProjs-exe
Last active February 27, 2026 19:50
Show Gist options
  • Select an option

  • Save YousufProjs-exe/4ac415c7f268c5b5bbc7790f73a15fcf to your computer and use it in GitHub Desktop.

Select an option

Save YousufProjs-exe/4ac415c7f268c5b5bbc7790f73a15fcf to your computer and use it in GitHub Desktop.
A Guessing Number game verses Computer (limit 100 ; Customize when can "i="in source code). Required JDK with IDE or Built in Compiler.
import java.util.Random;
import java.util.Scanner;
public class Game_3
{
public static void main(String args[])
{
System.out.println("Welcome");
Random rand = new Random();
Scanner in = new Scanner(System.in);
int n = rand.nextInt(100);
// limit can be changed by replacing "100" present above
int guess = -1;
while(guess != n)
{
System.out.println("Your try");
guess = in.nextInt();
if(guess > n)
System.out.println("Too High");
if(guess < n)
System.out.println("Too Low");
}
in.close();
System.out.println("You won");
//System.out.println("Credit: 25061-CS-010");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment