Java Programming Tutorial: Number Guessing Game


Video is ready, Click Here to View ×

We create a basic number guessing game for the user to try and guess a Random number created by the program.
Covers the creation of two object instances from the Scanner and Random classes. Explains how to use Google to search for Classes that might be of interest and how to read the Java API documents online related to a given Class. Compares the Java API online to the verbose popup dialogues used by Eclipse such as at the invocation of methods to a given object instance or static Class…

9 thoughts on “Java Programming Tutorial: Number Guessing Game

  1. Does not work for me:

    package project;

    import java.util.Scanner;
    import java.util.Random;

    class main{
    public static void main(String args[]){
    Scanner scan = new Scanner(;
    Random generator = new Random();

    final int MAX = 10; //can change later too
    int answer, guess;
    String another = "y";
    boolean flag = false;
    boolean anotherFlag = true;

    while(anotherFlag){ //while true
    answer = generator.nextInt(MAX) +1; //from 0-9 to 1-10

    System.out.print("I am thinking of a num between 1 and "
    + MAX + ".Can you guess what it is?");
    flag = false;
    while(flag){ //while false
    guess = scan.nextInt();

    if(guess == answer){
    System.out.println("You guess right.");
    flag = true;
    } else {
    System.out.println("Try again.");
    } //inner while loop

    System.out.println("Would you like to play again? (y/n)");
    another =;
    if(another.equalsIgnoreCase("y") == true){
    anotherFlag = true;
    } else {
    anotherFlag = false;
    } //outter while loop end

  2. Awesome program for beginners! Most other videos I've seen have advanced keywords that most people haven't been exposed to yet. I hate it when people use things that they wouldn't learn in a Java 101 class lol…

Leave a Reply

Your email address will not be published. Required fields are marked *